Added Canvas 1.1.0, originally not under SCM so no historical development records...
[canvas.git] / dispatcher.php
bloba10c09b936f918d8d4cffc78f5fea7de88a7bae1
1 <?php
2 // @role dispatcher
3 // @title Application Dispatcher
4 // @author Matt Todd
5 // @date 2005-11-26 4:48PM
6 // @desc Interprets requests, instanciates appropriate controller,
7 // and runs specified action with the appropriate Request data.
9 // timing
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__);
16 // load dependencies
17 include_once 'library/dependencies.php';
19 // extensions
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
27 // interpret request
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);
38 else
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);
46 // dispatch action
47 $controller->dispatch($action_name, $action_id, $request);
49 } catch(Exception $e) {
50 print_r($e);
53 // timing
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');