3 // @title Application Dispatcher
5 // @date 2005-11-26 4:48PM
6 // @desc Interprets requests, instanciates appropriate controller,
7 // and runs specified action with the appropriate Request data.
10 $GLOBALS['dispatch_time_begin'] = microtime(true);
12 { // required libraries and globals
13 // get the working directory for this web app (useful for ensuring security)
14 $GLOBALS['working_dir'] = dirname(__FILE__
);
17 include_once 'library/dependencies.php';
20 include_once Conventions
::extension_path("RSS"); // generates RSS feeds
23 try { // startup/boot logic
24 // handle sessions, initializations, & primary instanciations
25 if(class_exists('Session')) Session
::initialize(); // initialize Session
28 $request = new Request(Conventions
::path_info());
29 $controller_name = Conventions
::controller_name($request->controller
);
30 $helper_name = Conventions
::helper_name($request->controller
);
31 $action_name = Conventions
::action_name($request->action
);
32 $action_id = $request->id
;
34 { // handle instanciating request and executing requested function
35 // include controller classes
36 if(file_exists(Conventions
::controller_path($request->controller
)))
37 include_once Conventions
::controller_path($request->controller
);
39 Debug
::generic_exception_handler(new Exception("'{$controller_name}' does not exist"));
40 // includ helper (application or controller-specific)
41 if(file_exists(Conventions
::helper_path($request->controller
))) include_once Conventions
::helper_path($request->controller
); else $helper_name = "application_helper";
43 // instanciate controller
44 $controller = new $controller_name($request);
47 $controller->dispatch($action_name, $action_id, $request);
49 } catch(Exception
$e) {
54 $execution_time = round(microtime(true) - $GLOBALS['dispatch_time_begin'], 5);
55 $execution_memory = round(memory_get_usage()/1024, 2);
56 Debug
::log("Dispatched {$_SERVER['PATH_INFO']} ({$execution_time}sec/{$execution_memory}kb)", 'internal', 'notice', 'Dispatcher');