Start Writing Embeddable Applications

Posted on 8th May 2007 by Nio in 程序人生

Start Writing Embeddable Applications

…. If you're writing a standalone PHP application, maybe the next great forum software, or blog software, or wiki, or what have you, please design it in such a way that it is easily embeddable:

* When using configuration files, use a configuration component that doesn't require use of the global namespace (PEAR's Config, Solar's Solar_Config, and Zend Framework's Zend_Config come to mind); when coupled with a registry or implemented as a static class property (in PHP5), you can have access to the configuration from anywhere in your application.
* Have your bootstrap script call on class methods or functions to do their work. Don't do any decisioning in the global namespace.
* Better yet, use an MVC pattern in your apps, and have your bootstrap simply dispatch the controller. This can easily be duplicated in somebody else's code, or simply directly included.
* Make sure your templates are easily modified to allow developers to strip out header, footer, and menu elements.
* Create an API to allow retrieving necessary javascript and CSS so that it can later be injected into another system's templates.
* Don't use $_GLOBALS ever. It seems like an easy way to keep variables accessible across classes and functions, but with PHP 5's static properties, or judicious usage of singleton's in PHP 4, there are other ways to accomplish the same effect with fewer side effects.

No Comments »

No comments yet.

Leave a comment