예제 #1
0
 /**
  *
  */
 public function testPathWithLanguage()
 {
     $server = $this->getServerData();
     $server['PATH_INFO'] = '/no/test/';
     $request = new Request(['server' => $server, 'languages' => ['no' => 'nb_NO']]);
     $this->assertEquals('/test/', $request->path());
 }
예제 #2
0
 /**
  * Returns the current URL of the request.
  *
  * @access  public
  * @param   array    $queryParams  Associative array used to build URL-encoded query string
  * @param   string   $separator    Argument separator
  * @param   mixed    $language     Request language
  * @return  string
  */
 public function current(array $queryParams = [], $separator = '&', $language = true)
 {
     $queryParams = $queryParams ?: $this->request->get();
     return $this->to($this->request->path(), $queryParams, $separator, $language);
 }
예제 #3
0
 /**
  * Matches and returns the appropriate route along with its parameters.
  *
  * @access  public
  * @param   \mako\http\Request  $request  Request
  * @return  array
  */
 public function route(Request $request)
 {
     $matched = false;
     $parameters = [];
     $requestMethod = $request->method();
     $requestPath = $request->path();
     foreach ($this->routes->getRoutes() as $route) {
         if ($this->matches($route, $requestPath, $parameters)) {
             if (!$route->allows($requestMethod)) {
                 $matched = true;
                 continue;
             }
             // Redirect to URL with trailing slash if the route should have one
             if ($route->hasTrailingSlash() && !empty($requestPath) && substr($requestPath, -1) !== '/') {
                 return [$this->redirectRoute($requestPath), []];
             }
             // If this is an "OPTIONS" request then well collect all the allowed request methods
             // from all routes matching the requested path. We'll then add an "allows" header
             // to the matched route
             if ($requestMethod === 'OPTIONS') {
                 return [$this->optionsRoute($requestPath), []];
             }
             // Assign the route to the request
             $request->setRoute($route);
             // Return the matched route and parameters
             return [$route, $parameters];
         }
     }
     if ($matched) {
         // We found a matching route but it does not allow the request method so we'll throw a 405 exception
         throw new MethodNotAllowedException($this->getAllowedMethodsForMatchingRoutes($requestPath));
     } else {
         // No routes matched so we'll throw a 404 exception
         throw new NotFoundException($requestMethod . ': ' . $requestPath);
     }
 }