/** * @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; }
private static function getViewPostfix($responseType) { $availableViewsMap = array('text/xml' => '.xml.phtml', 'application/json' => '.json.phtml', 'text/json' => '.json.phtml'); $viewForType = Arrays::getValue($availableViewsMap, $responseType, false); if ($viewForType) { return $viewForType; } return Uri::isAjax() ? '.ajax.phtml' : '.phtml'; }
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; }; }
/** * @test * @dataProvider protocols * @param string $header * @param mixed $value * @param string $expected */ public function shouldReturnCorrectProtocol($header, $value, $expected) { //given $_SERVER[$header] = $value; //when $protocol = Uri::getProtocol(); //then $this->assertEquals($expected, $protocol); }
private function createParameters(RouteRule $routeRule, Uri $uri) { $parameters = $routeRule->getParameters() ? $routeRule->getParameters() : $uri->getParams(); $requestParameters = Uri::getRequestParameters(); return array_merge($parameters, $_POST, $_GET, $requestParameters); }
private function _redirect($url) { $url = Uri::addPrefixIfNeeded($url); $this->redirectHandler->redirect($url); }
public static function traceHttpRequest($params) { $uri = new Uri(); $requestDetails = $uri->getPathWithoutPrefix() . '#' . FrontController::$requestId; Session::push('stats_queries', $requestDetails, 'request_params', $params); }
private function needPrettyHandler() { $isHtmlResponse = ResponseTypeResolve::resolve() == "text/html"; return $isHtmlResponse && !Uri::isAjax(); }