Beispiel #1
0
 /**
  * preFilterRoutes
  *
  * @param RouteCollectionInterface $routes
  *
  * @return RouteCollectionInterface
  */
 protected function preFilterRoutes(Request $request, RouteCollectionInterface $routes)
 {
     if ($routes instanceof CachedCollection && ($sRoutes = $routes->findByStaticPath($request->getPath()))) {
         $routes = 0 !== count($sRoutes->all()) ? $sRoutes : $routes;
     }
     return $routes->findByMethod($request->getMethod());
 }
Beispiel #2
0
 private function matchHost(RouteContext $ctx, Request $request, $host = null)
 {
     if (null === $host) {
         return true;
     }
     return (bool) preg_match_all($ctx->getHostRegex(), $request->getHost());
 }
Beispiel #3
0
 /**
  * matchRequest
  *
  * @param Request $request
  *
  * @return MatchContext
  */
 public function matchRequest(Request $request, RouteCollectionInterface $routes)
 {
     $path = $request->getPath();
     $filtered = $this->filterByMethodAndScheme($routes, $request);
     if ($filtered instanceof CachedCollectionInterface && 0 !== count($r = $route->findByStaticPath($path))) {
         $filtered = $r;
     }
     $nomatch = array_diff_key($routes->all(), $filtered->all());
     foreach ($filtered->all() as $name => $route) {
         $rctx = $route->getContext();
         // does it match host?
         if (!$this->matchHost($rctx, $request, $route->getHost())) {
             $nomatch[$name] = $route;
             continue;
         }
         // does it match static path?
         if (0 !== strpos($path, $rctx->getStaticPath())) {
             continue;
         }
         // does it match pattern described on the route?
         if ((bool) preg_match_all($rctx->getRegex(), $path, $matches)) {
             $vars = $this->getMatchedVars($route, $matches);
             $handler = $route->getHandler();
             return new MatchContext(self::MATCH, $name, $request, $handler, $vars);
         }
         $nomatch[$name] = $route;
     }
     return new MatchContext($this->getMatchFailureReason($nomatch, $request), null, $request, null);
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function getPath()
 {
     return $this->request->getPath();
 }
Beispiel #5
0
 /**
  * getQueryString
  *
  * @param RequestContextInterface $req
  *
  * @return string
  */
 private function getQueryString(RequestContextInterface $req)
 {
     return $req->getQueryString() ? '?' . $req->getQueryString() : '';
 }