public function match(RequestContext $context) { if (null === $this->routes) { $this->routes = $this->loader->load($this->configuration); } $path = $context->getPath(); if (!($route = $this->routes->match($path))) { throw new RouteNotFoundException(sprintf('No route found for path %s.', $path)); } $method = $context->getMethod(); $allowedMethods = $route->getMethods(); if (count($allowedMethods) && !in_array($method, $allowedMethods)) { throw new MethodNotAllowedException($method, $allowedMethods); } return $route->getParameters(); }
public function testCreateFromRequest() { $request = new Request('GET', '/home', 'HTTP', '1.1'); $context = RequestContext::createFromRequest($request); $this->assertSame('GET', $context->getMethod()); $this->assertSame('/home', $context->getPath()); $this->assertSame('GET /home', (string) $context); }
private function doHandle(RequestInterface $request) { $context = RequestContext::createFromRequest($request); $action = $this->controllers->createController($this->router->match($context)); $response = call_user_func_array($action, [$request]); if (!$response instanceof ResponseInterface) { throw new \RuntimeException('A controller must return a Response object.'); } return $response; }
private function doHandle(RequestInterface $request) { $router = $this->getService('router'); $factory = $this->getService('controller_factory'); $context = RequestContext::createFromRequest($request); $action = $factory->createController($router->match($context)); if ($action instanceof AbstractAction) { $action->setServiceLocator($this->dic); } $response = call_user_func_array($action, [$request]); if (!$response instanceof ResponseInterface) { throw new \RuntimeException('A controller must return a Response object.'); } return $response; }
public function onKernelRequest(KernelEvent $event) { $request = $event->getRequest(); $context = RequestContext::createFromRequest($request); $request->setAttributes($this->router->match($context)); }