Exemple #1
0
 /**
  * @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;
 }
Exemple #2
0
 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';
 }
Exemple #3
0
 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;
     };
 }
Exemple #4
0
 /**
  * @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);
 }
Exemple #5
0
 private function createParameters(RouteRule $routeRule, Uri $uri)
 {
     $parameters = $routeRule->getParameters() ? $routeRule->getParameters() : $uri->getParams();
     $requestParameters = Uri::getRequestParameters();
     return array_merge($parameters, $_POST, $_GET, $requestParameters);
 }
Exemple #6
0
 private function _redirect($url)
 {
     $url = Uri::addPrefixIfNeeded($url);
     $this->redirectHandler->redirect($url);
 }
Exemple #7
0
 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();
 }