/** * AbstractController constructor. * @param Container $container * @param Request $request * @param \ReflectionClass $reflection_class */ public function __construct(Container $container, Request $request, \ReflectionClass $reflection_class) { $this->_container = $container; $this->_proxy = $container->get('proxy'); $this->_current = $request; $this->_response = new Response(); $this->_reflection_class = $reflection_class; }
/** * @return void */ public function run() { $this->before(); $container = new Container(); $container->registerBundles($this->getBundles()); $this->after($container); $container->get('proxy')->run(); }
/** * @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; }
public function t($key, $placeholders = []) { return $this->container->get('translator')->trans($key, $placeholders); }
private function getRouter() { return $this->container->get('proxy')->getRouter(); }