/**
  * @inheritDoc
  */
 public function match(Request $request)
 {
     // Must inject routes prior to matching.
     $this->injectRoutes();
     $path = $request->getUri()->getPath();
     $method = $request->getMethod();
     $params = $request->getServerParams();
     $params['REQUEST_METHOD'] = $method;
     $route = $this->router->match($path, $params);
     if (false === $route) {
         return $this->marshalFailedRoute($request);
     }
     return $this->marshalMatchedRoute($route);
 }
Esempio n. 2
0
 /**
  * Determine if the path in $_SERVER matches a registered route.
  * @return \Aura\Router\Route|bool
  */
 public function determineRouting()
 {
     $serverVars = $this->serverVars;
     if (!isset($serverVars['REQUEST_URI'])) {
         return false;
     }
     $path = parse_url($serverVars['REQUEST_URI'], PHP_URL_PATH);
     $this->lastRoute = $path;
     $result = $this->router->match($path, $serverVars);
     if (!$result) {
         return $result;
     }
     $authValidator = $this->requiresAuth($result->name);
     if ($authValidator) {
         $checker = $this->getRouteAuth($authValidator);
         $route = $checker->checkAuth($result);
         if ($route === $result) {
             return $result;
         }
         $result = $this->router->match($route, $serverVars);
         if (!$result) {
             throw new \LogicException('Both the route requested and the auth redirect route are invalid');
         }
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @param $pathinfo
  * @param Request $request
  *
  * @throws \Exception
  *
  * @return array
  */
 protected function doMatch($pathinfo, Request $request = null)
 {
     $matchedRoute = $this->router->match($pathinfo, $request->server->all());
     if ($matchedRoute === false) {
         throw new ResourceNotFoundException();
     }
     $routeParams = $matchedRoute->params;
     // The 'action' key always exists and defaults to the Route Name, so we check accordingly
     if (!isset($routeParams['controller']) && $routeParams['action'] === $matchedRoute->name) {
         throw new \Exception('Matched the route: ' . $matchedRoute->name . ' but unable to locate
         any controller/action params to dispatch');
     }
     // We need _controller, to that symfony ControllerResolver can pick this up
     if (!isset($routeParams['_controller'])) {
         if (isset($routeParams['controller'])) {
             $routeParams['_controller'] = $routeParams['controller'];
         } elseif (isset($routeParams['action'])) {
             $routeParams['_controller'] = $routeParams['action'];
         } else {
             throw new \Exception('Unable to determine the controller from route: ' . $matchedRoute->name);
         }
     }
     $routeParams['_route'] = $matchedRoute->name;
     // If the controller is an Object, and 'action' is defaulted to the route name - we default to __invoke
     if ($routeParams['action'] === $matchedRoute->name) {
         $routeParams['action'] = '__invoke';
     }
     if (false === strpos($routeParams['_controller'], '::') && isset($routeParams['action'])) {
         $routeParams['_controller'] = sprintf('%s::%s', $routeParams['_controller'], $routeParams['action']);
     }
     return $routeParams;
 }
Esempio n. 4
0
 /**
  * @param Request $request
  * @return RouteResult
  */
 public function match(Request $request)
 {
     $path = $request->getUri()->getPath();
     $params = $request->getServerParams();
     $route = $this->router->match($path, $params);
     if (false === $route) {
         return $this->marshalFailedRoute($request);
     }
     return $this->marshalMatchedRoute($route);
 }
Esempio n. 5
0
 /**
  * Searches for the target route on the router, returning it or false if it does not exist.
  *
  * @return \Aura\Router\Route|false
  */
 protected function matchRoute()
 {
     $this->matched_route = $this->router->match($this->request->getPathInfo(), $this->request->server->all());
     return $this->matched_route;
 }