Pines is a very complex framework, and has many different interacting parts. Understanding how these parts are loaded and when they become available to use is important in developing successful Pines software. If you are reading this book sequentially, you may be unfamiliar with some of the terms used in this section. Since this section is so important for Pines development, I recommend you come back to this section after reading Part II, and read it again to reinforce your understanding of the order in which Pines executes various parts of the system.
Pines begins execution by a request to the
index.php file.
Defines constants.
P_EXEC_TIME - The microtime
when the script began executing.
P_RUN - Used to determine that
Pines was executed properly through
index.php. You'll see this referenced
in every Pines PHP file.
P_BASE_PATH - The base path of
the Pines installation.
P_INDEX - The name of the index
file. (Almost always
index.php.)
P_SCRIPT_TIMING - Whether to
use the script timing system. Change this value to help
check for bottlenecks in your code.
Scans the system/init/ directory for
the system init scripts, and executes them in order.
i00timing.php
Loads script timing functions. These functions
will use the JavaScript
console.log function to display
timing information for various portions of the script
run.
i10functions.php
Loads various functions used by Pines Core and shortcut functions.
i20interfaces.php
Defines interfaces for system services and classes.
i30load_system.php
Strips slashes from request variables. This ensures that request data always appears as if Magic Quotes are turned off.
Loads system classes from
system/classes/.
Loads $pines.
Loads config service.
Loads system configuration.
Determines full and relative location using client provided hostname, if they are not already set by the config.
Sets
$pines->config->location to
static location, or relative location if static is
not set.
Loads info service.
Loads system info.
Loads hook service.
Loads depend service.
Loads default dependency checkers.
Loads menu service.
Loads page service.
Checks system config.
Determines current template from config setting or request variable and sets it as the template service.
Gets timezone from config and calls
date_default_timezone_set.
If offline mode is turned on, loads
system/offline.php, which ends
execution here.
If the current template's class file is
missing, loads
system/template_error.php,
which ends execution here.
Adds current template's class file to the list of class files.
Fills the lists of components and templates.
Finds components' class files and adds them to the list of class files.
Determines requested component and action, using URL rewriting if it is enabled.
i40init_system.php
Loads the class autoloader function. This function allows all component classes to be auto loaded the first time they are used.
Hooks the $pines
object.
Starts a session.
Displays any pending notices and errors found in the session and removes them from the session. This is part of the redirection system.
i50init_components.php
Scans all components' init directories for init scripts.
Adds the
system/i01common.php file to
the list.
Sorts them by filename.
Executes each init script in order. Some important events are noted below.
i00_ : Common cleaning functions can be overridden here.
i01_ : Common cleaning functions are being defined here.
i10_ : Components which provide system services should set themselves as the system service here.
i11_ : The user manager should ensure the session is filled with the current user's data here.
i12_ and i13_ : Any component which may log the user out (such as a timer) should do it here.
i14_ : Conditional and per user/group config should be loaded here.
i15_ : Any component which may change the requested component/action should do it here.
If a HttpClientException or HttpServerException is thrown, loads a module with "system" as component, "error" as view, and "content" as position. Assigns the exception to the exception property. The exception will return the correct HTTP status code, and the view will output a friendly message to the client.
Checks system config again in case config has
changed. (Repeats same steps as
$pines does when checking
config.)
i60action.php
Runs action, using the
requested component and action.
If a HttpClientException or HttpServerException is thrown, loads a module with "system" as component, "error" as view, and "content" as position. Assigns the exception to the exception property. The exception will return the correct HTTP status code, and the view will output a friendly message to the client.
i70kill_components.php
Scans all components' init directories for kill scripts.
Sorts them by filename.
Executes each kill script in order.
If a HttpClientException or HttpServerException is thrown, loads a module with "system" as component, "error" as view, and "content" as position. Assigns the exception to the exception property. The exception will return the correct HTTP status code, and the view will output a friendly message to the client.
i80menus.php
Loads the menu file
system/menu.json.
Loads each component's
menu.json file
consecutively.
Renders and attaches the menu.
Calculates each menu entry's dependencies and builds a multidimensional array of menu items whose dependencies are met.
Cleans each menu, removing any entry whose "children" dependency isn't met. Also removes some unnecessary data.
Creates and attaches a module for each menu,
the content of which is filled with the response of
the menu method of the
current template.
i90render.php
Calls the render
method of the page.
Returns the override document if override is set to true. (Does not do the steps immediately below.)
Iterates through each position, calling
render on all the modules
in that position.
Runs the template.php
file of the current template.
Echo the response.
As mentioned before, this section is very important for Pines development. Knowing when certain features will be available for use allows you to plan accordingly. Pines is very flexible, but it is also very strictly structured. If you know Pines' execution path, debugging will be much easier. Remember to come back to this section if you are currently unfamiliar with the features discussed here.