/** * Route the current URI * * @param string|Tamed\HTTP\Request $_request Request * @return Route matched route */ public function route($_request) { if ($this->hasStarted()) { return $this->_matchedRoute; } if ($_request instanceof Request) { $_request = $_request->getRequestUri(); } /** * Verifies for each route if it can be determined. If it can't, the default * will then be used. * * @var &$route Route */ foreach ($this->_routes as $name => &$route) { if ($route->match($_request)) { Debug::info('Route %s matched', $name); $this->_matchedRoute = $route; break; } } if ($this->_matchedRoute === null) { if (!isset($this->_routes['404'])) { throw new \Exception('No route to match'); } Debug::info('No route found : using 404'); $this->_matchedRoute = $this->_routes['404']; } return $this->_matchedRoute; }
/** * Sends the header * * @param bool $force forces the header to be sent... even if it was already sent */ public function send($force = false) { if ($this->_sent === false || $force === true) { $header = $this->_header . ': ' . $this->_value; if ($this->_value === null) { $header = $this->_header; } Debug::info('Sending header (%1$s, code %2$d)', $header, $this->_status); \header($header, $this->_replace, $this->_status); $this->_sent = true; } }
case E_USER_NOTICE: case E_DEPRECATED: case E_NOTICE: case E_STRICT: default: $err = Debug::LEVEL_INFO; break; } $e = new \ErrorException($errstr, 0, $errno, $errfile, $errline); Debug::log('An error occurred (' . $e->__toString() . ')', $err); throw $e; }); Obj::$config = new Configuration_Loader(__DIR__ . '/../conf/'); Obj::$router = new Router(); $routes = Obj::$config->get('routes', function (&$v, $k) { // -- if a 'app' part is not set, it has to be constructed if (!isset($v['app'])) { if (!isset($v['controller'], $v['action'])) { throw new \Exception('The route does not have the required arguments'); } $v['app'] = $v['controller'] . ':' . $v['action']; } $v = new Route($v['app'], $v['pattern']); }); foreach ($routes as $name => &$route) { Debug::info('Adding route %s', (string) $name); Obj::$router->addRoute($name, $route); } /* * EOF */
/** * Forwards to a new controller and a new action * * Note : the controller should be in in full qualified form (namespaces included) * * @param string $_controller Controller's name * @param string $_action Action's name */ protected final function _forward($_controller, $_action) { Debug::info('Forwarding to "%1$s->%2$s"', $_controller, $_action); /** * @var Front */ $controller = new $_controller($this->_request, $this->_response, $this->_view); $controller->_isForwarded = true; $controller->_main($_action); }