* @return void * @ignore */ function benchmark_timer_stop() { if (!mvc_dev_can_print()) { return; } global $benchmarkTimer; print ' - ' . $benchmarkTimer->stop() . ', ' . intval(1.0 / $benchmarkTimer->getRealTime()) . ' requests/second'; } } ######################################################################## define('MVC_DIR', APPLICATION_DIR . 'lib/mvc/'); try { MVCRouter::findDestination(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/')->execute(); } catch (MVCTemplateNotFoundException $e) { require_once MVC_DIR . 'event.d/template_not_found_exception.php'; } catch (MVCActionNotFoundException $e) { require_once MVC_DIR . 'event.d/action_not_found_exception.php'; } catch (MVCRouterException $e) { require_once MVC_DIR . 'event.d/router_exception.php'; } catch (MVCException $e) { require_once MVC_DIR . 'event.d/mvc_exception.php'; } catch (Exception $e) { require_once MVC_DIR . 'event.d/exception.php'; } # stop timer if dev if (MVC_DEV_MODE) { benchmark_timer_stop(); }
/** * @return void */ public function execute() { if (!isset($_REQUEST['controller'])) { throw new MVCRouterException('Missing controller'); } # get controller name $controller_name =& $_REQUEST['controller']; if (strpos($controller_name, '_') !== false) { $controller_name = strtolower($controller_name); } elseif (ctype_upper($controller_name[0])) { $controller_name = Inflector::underscore($controller_name); } # get controller class $controller_class = Inflector::camelize($controller_name) . 'Controller'; # require app controller if (!@(include_once APPLICATION_DIR . 'app/controllers/application.php')) { error_log("No application controller found! Looked for " . APPLICATION_DIR . 'app/controllers/application.php'); throw new MVCRouterException('No application controller found!'); } # load controller if (!@(include_once APPLICATION_DIR . 'app/controllers/' . $controller_name . '_controller.php')) { throw new MVCRouterException("Can not find controller '{$controller_name}'"); } # instantiate controller $controller = new $controller_class(); MVCRouter::$controller = $controller; # set controller properties $controller->name = $controller_name; $controller->action_name = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'index'; # execute action ob_start(); try { $_action = $controller->action_name; $controller->{$_action}; #call_user_func(array($controller, $controller->action_name)); # render template (if not allready explicitly rendered by controller) if (!MVCTemplate::$has_rendered) { # we want MVCTemplate to use MVCRouter::$controller instead of controller from request if (isset($_REQUEST['controller'])) { unset($_REQUEST['controller']); } MVCTemplate::render($controller->action_name, $_REQUEST); } # finalize response $content_for_layout = ob_get_clean(); if (!@(include APPLICATION_DIR . 'app/views/layouts/' . $controller->name . '.phtml')) { # Missing layout for controller - render content directly print $content_for_layout; } } catch (Exception $e) { ob_end_clean(); throw $e; } }