/** * @return RouteRule * @throws RouterException */ public function findRoute() { $path = $this->uri->getPathWithoutPrefix(); $requestType = Uri::getRequestType(); $rule = $this->findRouteRule($path, $requestType); if (!$rule) { throw new RouterException('No route rule found for HTTP method [' . $requestType . '] and URI [' . $path . ']'); } $rule->setParameters($path); return $rule; }
public static function protect(Controller $controller) { $controller->before[] = function () { if (CsrfProtector::isMethodProtected(Uri::getRequestType())) { CsrfProtector::validate(); } return true; }; $controller->after[] = function () use($controller) { $controller->setCookie(array('name' => 'csrftoken', 'value' => CsrfProtector::getCsrfToken(), 'expire' => 0, 'path' => '/')); return true; }; }