Пример #1
0
 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();
 }
Пример #2
0
 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);
 }
Пример #3
0
 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;
 }
Пример #4
0
 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;
 }
Пример #5
0
 public function onKernelRequest(KernelEvent $event)
 {
     $request = $event->getRequest();
     $context = RequestContext::createFromRequest($request);
     $request->setAttributes($this->router->match($context));
 }