OSCON 2011 - Making Your PHP Application Easy to Customize

1,442 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,442
On SlideShare
0
From Embeds
0
Number of Embeds
36
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 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.
  • OSCON 2011 - Making Your PHP Application Easy to Customize

    1. 1. Making Your PHP Application Easy to Customize<br />John Mertic<br />@2010 SugarCRM Inc. All rights reserved.<br />
    2. 2. Who Am I?<br />John Mertic<br />http://jmertic.wordpress.com<br />Twitter: @jmertic<br />jmertic@sugarcrm.com ( Work )<br />jmertic@php.net ( PHP )<br />Community Manager for SugarCRM<br />http://www.sugarcrm.com<br />Read our blog at http://developers.sugarcrm.com/wordpress<br />3/24/2011<br />@2011 SugarCRM Inc. All rights reserved.<br />2<br />
    3. 3. My books<br />3/24/2011<br />@2011 SugarCRM Inc. All rights reserved.<br />3<br />http://amzn.to/enioPV<br />http://t.co/UFRHNSO<br />
    4. 4. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />Why should my app be easy to customize?<br />4<br />Source http://www.flickr.com/photos/duncan/4782911809<br />
    5. 5. So how should you do this?<br />
    6. 6. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />6<br />Make your code open<br />Source http://www.flickr.com/photos/igalko/4502271194<br />
    7. 7. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />7<br />Starting off with a good file structure<br />
    8. 8. Things good to do here<br />File naming convention<br />Zend Framework approach<br />Class Zend_Db_Table is at "Zend/Db/Table.php”<br />Abstract class Zend_Controller_Request_Abstract is at “Zend/Controller/Request/Abstract.php”<br />Interface Zend_Validate_Interface is at “Zend/Validate/Interface.php”<br />Allowing file/class overrides<br />SugarCRM approach<br />Can drop in a replacement file in the same location in the custom/ directory<br />Example: Override Contact’s detail view by dropping in a view.detail.php file in the custom/modules/Contacts/views/ directory.<br />7/27/11<br />@2010 SugarCRM Inc. All rights reserved.<br />8<br />
    9. 9. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />9<br />Source http://www.flickr.com/photos/cype_applejuice/43750657<br />Code Design<br />
    10. 10. Dependency Injection<br />class Widgets<br />{<br /> protected $_dbConn;<br /> public function __construct()<br /> {<br /> $this->_dbConn = DBFactory::getInstance();<br /> }<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />10<br />
    11. 11. Dependency Injection<br />class Widgets<br />{<br /> protected $_dbConn;<br /> public function __construct( DBInstance $dbConn )<br /> {<br /> $this->_dbConn = $dbConn;<br /> }<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />11<br />
    12. 12. Dependency Injection<br />class Widgets<br />{<br /> protected $_dbConn;<br /> public function __construct() { }<br /> public function setDBConnection( <br />DBInstance$dbConn )<br /> {<br /> $this->_dbConn = $dbConn;<br /> }<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />12<br />
    13. 13. Interfaces and Abstracts<br />interface LoggerTemplate<br />{<br /> /**<br /> * Main method for handling logging a message to the logger<br /> *<br /> * @param string $level logging level for the message<br /> * @param string $message<br /> */<br /> public function log(<br /> $method,<br /> $message<br /> );<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />13<br />
    14. 14. Interfaces and Abstracts<br />abstract class loc_xml extends source<br />{<br /> public function __parse($file)<br /> {<br /> $contents = file_get_contents($file);<br /> return simplexml_load_string($contents);<br /> }<br /> public abstract function getItem(<br /> $args=array(), <br /> $module=null);<br /> public abstract function getList(<br /> $args=array(), <br /> $module=null);<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />14<br />
    15. 15. Factory Loaders<br />class ControllerFactory<br />{<br /> /**<br /> * Obtain an instance of the correct controller.<br /> * <br /> * @return an instance of SugarController<br /> */<br /> function getController($module)<br /> {<br /> $class = ucfirst($module).'Controller';<br /> $customClass = 'Custom' . $class;<br /> if(file_exists('custom/modules/'.$module.'/controller.php')){<br /> $customClass = 'Custom' . $class; <br />require_once('custom/modules/'.$module.'/controller.php');<br /> if(class_exists($customClass)){<br /> $controller = new $customClass();<br /> }else if(class_exists($class)){<br /> $controller = new $class();<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />15<br />
    16. 16. Factory Loaders<br /> }elseif(file_exists('modules/'.$module.'/controller.php')){ <br />require_once('modules/'.$module.'/controller.php');<br /> if(class_exists($customClass)){<br /> $controller = new $customClass();<br /> }else if(class_exists($class)){<br /> $controller = new $class();<br /> }<br /> }else{<br /> if(file_exists('custom/include/MVC/Controller/SugarController.php')){<br />require_once('custom/include/MVC/Controller/SugarController.php');<br /> }<br /> if(class_exists('CustomSugarController')){<br /> $controller = new CustomSugarController();<br /> }else{<br /> $controller = new SugarController();<br /> }<br /> }<br />$controller->setup($module);<br /> return $controller;<br /> }<br />}<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />16<br />
    17. 17. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />17<br />Document it!<br />Source: http://www.flickr.com/photos/nicecupoftea/3218211407<br />
    18. 18. Ways to do this<br />Docblock comments<br />Example code<br />Short blog posts/articles<br />Forums / Mailing List<br />Wiki<br />Architectural documentation<br />Full blown developer guide<br />7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />18<br />
    19. 19. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />19<br />Source: http://www.flickr.com/photos/code_martial/4145914957<br />Learn from your developers<br />
    20. 20. 7/22/2010<br />@2010 SugarCRM Inc. All rights reserved.<br />20<br />Questions?<br />To contact me after my presentation, text 2OR to INTRO (46876)<br />

    ×