vendor/symfony/framework-bundle/Controller/ControllerResolver.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\Controller;
  11. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  12. use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
  13. /**
  14.  * @author Fabien Potencier <fabien@symfony.com>
  15.  *
  16.  * @final
  17.  */
  18. class ControllerResolver extends ContainerControllerResolver
  19. {
  20.     /**
  21.      * {@inheritdoc}
  22.      */
  23.     protected function instantiateController($class): object
  24.     {
  25.         return $this->configureController(parent::instantiateController($class), $class);
  26.     }
  27.     private function configureController($controllerstring $class): object
  28.     {
  29.         if ($controller instanceof ContainerAwareInterface) {
  30.             $controller->setContainer($this->container);
  31.         }
  32.         if ($controller instanceof AbstractController) {
  33.             if (null === $previousContainer $controller->setContainer($this->container)) {
  34.                 throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?'$class));
  35.             } else {
  36.                 $controller->setContainer($previousContainer);
  37.             }
  38.         }
  39.         return $controller;
  40.     }
  41. }