PHPLights/Documentation/Global objects

From Linuxnetworks
< PHPLights‎ | Documentation
Revision as of 23:25, 3 September 2007 by Nose (Talk | contribs)

Jump to: navigation, search

Global objects

There are two objects which are available everywhere in the application: The context (LsContext) and the configuration (LsConfig). Both are classes with static methods and don't need to be instantiated to be usable.

The context stores references to created objects during bootstrapping. This does include:

  • logging
  • configuration
  • request object
  • response object
  • database manager
  • user object
  • timer

The request object provides access to the available parameters given by the server. It stores references to the GET, POST, REQUEST, ENV and SERVER variables. Using get() on the request object requires a regular expression which is used to check if the value which belongs to the key is what is expected by the application. Otherwise, a security exception is thrown.

The response object is the opposite of the request object and it saves the prepared views until the output is finally generated by the dispatcher.

Authentication and access controll mechanisms are provided by the user object.

Finally, the timer has invaluable information for performance optimizations. Each time the add() function is called, the time difference to the last call is stored and is available in the debug view.

Front Controller

Applications based on PHPLights provide a single entry for all pages through their index.php file in the application directory. It starts up the library core which initializes the basic library components and sets up class autoloading.

Afterwards, the dispatcher forwards the request to the appropriate controller and action method. Controller, action and parameter are given via the URL, e.g.

index.php/default/index/2007/print

would specify the controller "default", the action "index" and the parameters "2007" and "print". The first two parameter after "index.php" are mapped the "index" method in the "DefaultController" class. All other parameter are available as numerically indexed array via the get() function of the request class:

$req = LsContext::getRequest()
$list = $req->get('ls/param', array(), $regex );

Controller class and its methods must be implemented by the application and contains the business logic necessary to fulfill the request.