コード例 #1
0
ファイル: RouteMatcher.php プロジェクト: abava/routing
 /**
  * @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());
     }
 }
コード例 #2
0
ファイル: RouteMatcherSpec.php プロジェクト: abava/routing
 function let(RouteParser $parser, FastrouteDispatcherFactory $factory, Route $route, Dispatcher $dispatcher)
 {
     $parser->parse(Argument::containing($route->getWrappedObject()))->willReturn(['parsed']);
     $factory->create(['parsed'])->willReturn($dispatcher);
     $this->beConstructedWith($parser, $factory);
 }