User Tools

Site Tools


dev:core:page-lifecycle

Page lifecycle

Oxwall is under developement at the moment, so below you can see only preliminary version of page-lifecycle. Oxwall implements front-controller pattern and all requests are handled by single script - index.php (it is the only script available for user requests). Lets see how it works:

First of all .htaccess file in root directory helps us to redirect all requests to front-controller script.

Code of .htaccess:

Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php

Below you can see the code of index.php script:

Code of index.php:

define('_OW_', true);
 
define('DS', DIRECTORY_SEPARATOR);
 
define('OW_DIR_ROOT', dirname(__FILE__).DS );
 
require_once(OW_DIR_ROOT.'includes'.DS.'init.php');
 
$application = OW_Application::getInstance();
 
$application->triggerEvent(OW_EventManager::APPLICATION_INIT);
 
$application->triggerEvent(OW_EventManager::ROUTE_STARTUP);
 
$application->route();
 
$application->triggerEvent(OW_EventManager::ROUTE_SHUTDOWN);
 
$application->dispatch();
 
$application->finalize();
 
$application->returnResponse();

As we can see index.php is very simple script representing a number of definite logic steps:

 <-- Page start -->

Define 3 basic constants

  • _OW_ - is indicator if core and other classes are included within the OW framework (kind of replacement for 'deny from all' instruction)
  • DS - short variant of standart PHP constant DIRECTORY_SEPARATOR
  • OW_DIR_ROOT - root directory constant for OW script modules

Include init.php script (loads modules for application startup)

  • load constants and configs to run the appliaction (stored in separate PHP files - define.php and configs.php)
  • load global functions (function.php)
  • load classes to be used by application in any case
  • register autoloader and error manager (exception interceptor, PHP error handler)

Create an instance of front-controller class (OW_Application) and initialize it

  • register non-autoloadable classes in autoloader object (Form, Inputs, etc)
  • add static routes from navigation system (static pages added from admin panel) in router object
  • register active plugins in plugin manager and load plugin init.php scripts (plugin initializers)
  • initialize core basic objects: request, response, event manager, theme manager, etc
  • create and add HTML document (OW_HtmlDocument) to response object

Trigger event APPLICATION_INIT

 <-- User request handling start -->

Route requested uri (Routing process)

  • search matching route in static navigation routes
  • — in custom static routes
  • — in dynamic routes
  • try to resolve requested uri with system default route
 <-- If matches were not found -> show 404 page -->

Trigger event ROUTE_SHUTDOWN

Dispatch routing results (dispatching process)

  • Check provided dispatch parameters
  • Create action controller instance;
  • Run controller action;
  • Get result markup and put it in HTML document object

Trigger event FINALIZE

Compile and send response

  • Compile document to send ( controller rendered body + master_page + html head part )
  • send added HTTP headers
  • send buffered debug output
  • send compiled HTML document
 <-- Page end (Here script dies) -->
dev/core/page-lifecycle.txt · Last modified: 2013/02/15 03:43 by Den