public static function create(\Carbo\Routing\Router &$router, array $map = []) { foreach ($map as $mapping) { $route = $mapping[0]; if ($route instanceof Mapper) { $router->route($route); } else { $view = array_slice($mapping, 1); if (is_numeric($route)) { $router->error($route, $view); } else { if (!is_string($view[0])) { $router->route(self::constructMapperFromRoute($route, $view[0])); } else { $router->route(self::constructMapperFromRoute($route, $view)); } } } } }
public function serveView(View $view, array $mapper_params = []) { $view->authenticator = $this->authenticator; if ($view instanceof IAuthenticated) { if ($this->authenticator->isAuthenticated()) { return parent::serveView($view, $mapper_params); } else { throw new Http\CodeException(Http\Code::Forbidden); } } else { return parent::serveView($view, $mapper_params); } }
protected function getResponse(View $view) { if ($view instanceof ICacheable) { if ($cached_response = $this->fromCache($view->hash())) { $view->headers['X-Cache'] = 'hit'; return $cached_response; } else { $view->headers['X-Cache'] = 'miss'; $fresh_response = parent::getResponse($view); $this->toCache($fresh_response, $view->hash(), $view->expire()); return $fresh_response; } } return parent::getresponse($view); }