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(string $class): object
  24.     {
  25.         $controller parent::instantiateController($class);
  26.         if ($controller instanceof ContainerAwareInterface) {
  27.             $controller->setContainer($this->container);
  28.         }
  29.         if ($controller instanceof AbstractController) {
  30.             if (null === $previousContainer $controller->setContainer($this->container)) {
  31.                 throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?'$class));
  32.             } else {
  33.                 $controller->setContainer($previousContainer);
  34.             }
  35.         }
  36.         return $controller;
  37.     }
  38. }