/**
  * @inheritDoc
  */
 public function getRoutes() : array
 {
     $routes = [];
     foreach ($this->routes->getRoutes() as $route) {
         if ((!$route->getHost() || $route->getHost() === $this->request->getUri()->getHost()) && (!$route->getScheme() || $route->getScheme() === $this->request->getUri()->getScheme())) {
             $routes[] = $route;
         }
     }
     return $routes;
 }
Beispiel #2
0
 function it_throws_not_found_exception(ServerRequestInterface $request, RouteCollection $routeCollection, Route $route, UriInterface $uri, Dispatcher $dispatcher)
 {
     $routeCollection->getRoutes()->willReturn([$route]);
     $request->getUri()->willReturn($uri);
     $uri->getPath()->willReturn('/url');
     $request->getMethod()->willReturn('GET');
     $dispatcher->dispatch('GET', '/url')->willReturn([Dispatcher::NOT_FOUND]);
     $this->shouldThrow(NotFoundException::class)->match($request, $routeCollection);
 }
 function it_filters_decorated_collection_on_get_goutes(RouteCollection $collection, ServerRequestInterface $request, UriInterface $uri)
 {
     $route1 = (new Route(['GET'], '/url1', 'responder1'))->withHost('localhost');
     $route2 = (new Route(['GET'], '/url2', 'responder2'))->secure();
     $route3 = new Route(['GET'], '/url3', 'responder3');
     $collection->getRoutes()->willReturn([$route1, $route2, $route3]);
     $request->getUri()->willReturn($uri);
     $uri->getHost()->willReturn('host');
     $uri->getScheme()->willReturn('http');
     $this->getRoutes()->shouldBe([$route3]);
 }
Beispiel #4
0
 /**
  * @inheritDoc
  */
 public function match(ServerRequestInterface $request, RouteCollectionContract $routeCollection) : RouteContract
 {
     $routes = $routeCollection->getRoutes();
     $parsedRouteData = $this->parser->parse($routes);
     $dispatcher = $this->fastrouteDispatcherFactory->create($parsedRouteData);
     $match = $dispatcher->dispatch($request->getMethod(), $request->getUri()->getPath());
     switch ($match[0]) {
         case $dispatcher::FOUND:
             /** @var RouteContract $route */
             list(, $route, $variables) = $match;
             return $route->withVariables($variables);
         case $dispatcher::METHOD_NOT_ALLOWED:
             throw new NotAllowedException($match[1]);
         default:
             throw new NotFoundException($request->getMethod(), $request->getUri()->getPath());
     }
 }