PHP2Go Design Patterns

Output content buffer: The HTML documents are built using a nested set of templates and components, each of them generating a piece of HTML code. The final content is echoed in the end of the execution chain. Therefore, all the documents may be built in separated pieces, each one generated by a user class method or function.

Output compression: All the HTML documents built with PHP2Go can be sent to the client using output compression. Using this approach, you can decrease the response time of the application. The zlib extension is the only requirement to enable this feature.

Database Transparency: The database connectivity is implemented by ADODb, a database library built by John Lim, created to provide portable database applications using PHP. PHP2Go provides a layer (php2go.db.Db) that contains calls to the most important methods of ADOConnection class. Currently, there's no support for other database libraries like PEAR::DB.

Template Engine: The goal on using templates is to separate code logic from HTML code when developing systems so that they can be easily customized and maintained. PHP2Go has its own template engine, deriving concepts from TemplatePower and Smarty. It supports advanced variable handling, global variables, dynamic blocks, include statements, conditional tags (IF, ELSE IF, ELSE, END IF), iteration tags (LOOP, ELSE LOOP, END LOOP), variable modifiers and widgets.

Error Reporting system: All errors occurred in an application built with PHP2Go will be handled by an error handler function included in the download package. According to the configuration settings, the framework can catch this errors, ignore certain errors or warnings, log the messages in a text file in the server, add debug trace information and, finally, show the error information using HTML. The database errors are also handled, but using another error handler.

Singleton: Some of the most important and useful classes in PHP2Go have a method called getInstance. These are static methods that store in a static variable a single instance of the class. When called, they return a reference that points to that single instance. Database connection class, language and configuration objects are some examples of that pattern.

Factory Methods: Static methods that create an instance of an object receiving its "type" as parameter. The factory method translates the parameter into a valid class name, imports and instantiates the class, returning the created instance. Datasets, for example, can be instantiated using DataSet::getInstance($type), where $type is 'db', 'xml' or 'csv'.

Destructor Methods: The PHP5 destructors (__destruct) are declared in the most important classes inside PHP2Go. Even when the framework is running in an older version (>= 4.3.0 and <= 5.0.0), an emulated object destruction routine is executed in the script shutdown.

Full Object Orientation: From the simplest function to the most complex routine, 99% of the PHP code available in PHP2Go is inside classes. Besides, almost all the classes are included in an object hierarchy, whose root is the class PHP2Go (a java.lang.Object port).

Form Definition using XML: All the sections, fields and buttons used in the form API of PHP2Go can be defined in a XML file. Each form component has a tag in the document type definition, with some customization attributes. The XML specification also allows the developer to specify validation rules, Javascript event handlers to the fields, options and buttons and conditional sections (to implement access control)

[View PHP2Go Forms DTD]

Report Definition using XML: Almost all the web systems have a list of data splitted into pages. php2go.data.Report is a class that generates HTML reports using a XML definition file and a template file that defines the disposition of the lines and cells. The XML file contains the SQL query of the report and can contain data filters, which code and logic is automatically generated and processed by the framework.

[View PHP2Go Reports DTD]