What Are The Drone Anti-jamming Systems Technology?
OSCON 2011 - Making Your PHP Application Easy to Customize
1. Making Your PHP Application Easy to Customize John Mertic @2010 SugarCRM Inc. All rights reserved.
2. Who Am I? John Mertic http://jmertic.wordpress.com Twitter: @jmertic jmertic@sugarcrm.com ( Work ) jmertic@php.net ( PHP ) Community Manager for SugarCRM http://www.sugarcrm.com Read our blog at http://developers.sugarcrm.com/wordpress 3/24/2011 @2011 SugarCRM Inc. All rights reserved. 2
3. My books 3/24/2011 @2011 SugarCRM Inc. All rights reserved. 3 http://amzn.to/enioPV http://t.co/UFRHNSO
4. 7/22/2010 @2010 SugarCRM Inc. All rights reserved. Why should my app be easy to customize? 4 Source http://www.flickr.com/photos/duncan/4782911809
8. Things good to do here File naming convention Zend Framework approach Class Zend_Db_Table is at "Zend/Db/Table.php” Abstract class Zend_Controller_Request_Abstract is at “Zend/Controller/Request/Abstract.php” Interface Zend_Validate_Interface is at “Zend/Validate/Interface.php” Allowing file/class overrides SugarCRM approach Can drop in a replacement file in the same location in the custom/ directory Example: Override Contact’s detail view by dropping in a view.detail.php file in the custom/modules/Contacts/views/ directory. 7/27/11 @2010 SugarCRM Inc. All rights reserved. 8
9. 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 9 Source http://www.flickr.com/photos/cype_applejuice/43750657 Code Design
10. Dependency Injection class Widgets { protected $_dbConn; public function __construct() { $this->_dbConn = DBFactory::getInstance(); } } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 10
11. Dependency Injection class Widgets { protected $_dbConn; public function __construct( DBInstance $dbConn ) { $this->_dbConn = $dbConn; } } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 11
12. Dependency Injection class Widgets { protected $_dbConn; public function __construct() { } public function setDBConnection( DBInstance$dbConn ) { $this->_dbConn = $dbConn; } } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 12
13. Interfaces and Abstracts interface LoggerTemplate { /** * Main method for handling logging a message to the logger * * @param string $level logging level for the message * @param string $message */ public function log( $method, $message ); } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 13
14. Interfaces and Abstracts abstract class loc_xml extends source { public function __parse($file) { $contents = file_get_contents($file); return simplexml_load_string($contents); } public abstract function getItem( $args=array(), $module=null); public abstract function getList( $args=array(), $module=null); } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 14
15. Factory Loaders class ControllerFactory { /** * Obtain an instance of the correct controller. * * @return an instance of SugarController */ function getController($module) { $class = ucfirst($module).'Controller'; $customClass = 'Custom' . $class; if(file_exists('custom/modules/'.$module.'/controller.php')){ $customClass = 'Custom' . $class; require_once('custom/modules/'.$module.'/controller.php'); if(class_exists($customClass)){ $controller = new $customClass(); }else if(class_exists($class)){ $controller = new $class(); } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 15
16. Factory Loaders }elseif(file_exists('modules/'.$module.'/controller.php')){ require_once('modules/'.$module.'/controller.php'); if(class_exists($customClass)){ $controller = new $customClass(); }else if(class_exists($class)){ $controller = new $class(); } }else{ if(file_exists('custom/include/MVC/Controller/SugarController.php')){ require_once('custom/include/MVC/Controller/SugarController.php'); } if(class_exists('CustomSugarController')){ $controller = new CustomSugarController(); }else{ $controller = new SugarController(); } } $controller->setup($module); return $controller; } } 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 16
17. 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 17 Document it! Source: http://www.flickr.com/photos/nicecupoftea/3218211407
18. Ways to do this Docblock comments Example code Short blog posts/articles Forums / Mailing List Wiki Architectural documentation Full blown developer guide 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 18
19. 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 19 Source: http://www.flickr.com/photos/code_martial/4145914957 Learn from your developers
20. 7/22/2010 @2010 SugarCRM Inc. All rights reserved. 20 Questions? To contact me after my presentation, text 2OR to INTRO (46876)
Notas del editor
So CRM is not about technology butall about Customers, YOUR Customers.
User base is diverse, likes different offerings, and will move between them.Lots of choices ( Web Servers / OSes / Databases / PHP versions ) as well as config possibilitiesHave to cover lots of platforms; can rely on particular hardware or software being available.
User base is diverse, likes different offerings, and will move between them.Lots of choices ( Web Servers / OSes / Databases / PHP versions ) as well as config possibilitiesHave to cover lots of platforms; can rely on particular hardware or software being available.
User base is diverse, likes different offerings, and will move between them.Lots of choices ( Web Servers / OSes / Databases / PHP versions ) as well as config possibilitiesHave to cover lots of platforms; can rely on particular hardware or software being available.