Example #1
0
 function it_matches_and_dispatches_route(RouteMatcher $matcher, MiddlewarePipelineFactory $pipelineFactory, RouteCollection $routes, RouteDispatcherFactory $dispatcherFactory, RequestRouteCollectionFactory $requestRouteCollectionFactory, Route $route, MiddlewarePipeline $pipeline, RouteDispatcher $routeDispatcher, ServerRequestInterface $request, ResponseInterface $response)
 {
     $matcher->match($request, $routes)->willReturn($route);
     $route->getMiddlewares()->willReturn(['middleware']);
     $pipelineFactory->create(['middleware'])->willReturn($pipeline->getWrappedObject());
     $dispatcherFactory->create($route)->willReturn($routeDispatcher);
     $pipeline->process($request, $routeDispatcher)->willReturn($response);
     $requestRouteCollectionFactory->create($routes, $request)->willReturn($routes);
     $this->next($request)->shouldBe($response);
 }
Example #2
0
 /**
  * @inheritDoc
  */
 public function next(ServerRequestInterface $request) : ResponseInterface
 {
     $requestRouteCollection = $this->routeCollectionFactory->create($this->routes, $request);
     // Find matching route against provided request.
     $route = $this->matcher->match($request, $requestRouteCollection);
     // Create route middleware pipeline.
     $pipeline = $this->pipelineFactory->create($route->getMiddlewares());
     // Create the last delegate, which calls route handler.
     $routeDispatcher = $this->dispatcherFactory->create($route);
     return $pipeline->process($request, $routeDispatcher);
 }
Example #3
0
 /**
  * @inheritDoc
  */
 public function handle(InputInterface $input, OutputInterface $output)
 {
     $uri = new Uri($this->arg('path'));
     if ($input->getOption('host')) {
         $uri = $uri->withHost($input->getOption('host'));
     }
     if ($input->getOption('scheme')) {
         $uri = $uri->withScheme($input->getOption('scheme'));
     }
     $request = $this->requestFactory->createServerRequest($input->getOption('method'), $uri);
     try {
         $route = $this->matcher->match($request, $this->collector);
         $table = new Table($output);
         $table->setHeaders(['Methods', 'Path', 'Action', 'Name', 'Host', 'Scheme', 'Middlewares']);
         $table->addRow([join(',', $route->getMethods()), $route->getPath(), is_string($route->getCallable()) ? $route->getCallable() : get_class($route->getCallable()), $route->getName(), $route->getHost(), $route->getScheme(), join(',', array_keys($route->getMiddlewares()))]);
         $table->render();
     } catch (RouteNotFoundException $e) {
         $output->writeln('<error>Path cannot be matched against defined routes</error>');
     } catch (MethodNotAllowedException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
     }
 }