Example #1
0
 /**
  * @param Request $request
  * @return Response
  * @throws ProxyException
  */
 protected function executeRequest(Request $request)
 {
     $this->request_pool[] = $request;
     if ($request === $this->initial && !in_array($request->getAction(), $this->router->getAllowedActions())) {
         $this->pageNotFoundException();
     }
     if ($request !== $this->main && in_array($request->getAction(), $this->router->getAllowedActions())) {
         throw new ProxyException('Action "' . $request->getAction() . '" is reserved by router for main requests, so can not be used for other requests.');
     }
     $definition = $request->getBundle() . '.' . $request->getResource();
     if ($this->container->has($definition)) {
         $controller = $this->container->get($definition);
     } else {
         try {
             $reflection_class = new \ReflectionClass($request->getController());
             $controller = $reflection_class->newInstance($this->container, $request, $reflection_class);
             if (!method_exists($controller, $request->getAction())) {
                 if ($request === $this->initial) {
                     $this->pageNotFoundException();
                 } else {
                     throw new ProxyException('Action "' . $request->getAction() . '" not found in controller "' . $request->getController() . '".');
                 }
             }
         } catch (\ReflectionException $e) {
             if ($request === $this->initial) {
                 $this->pageNotFoundException();
             } else {
                 throw new ProxyException('Controller "' . $request->getController() . '" not found.');
             }
         }
     }
     /** @var ControllerInterface $controller */
     $response = $controller->_run();
     if (!$response instanceof Response) {
         throw new ProxyException('Method "_run" of controller must return object of type Response.');
     }
     return $response;
 }