vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php line 43

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 Psr\Log\LoggerInterface;
  12. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
  15. /**
  16.  * @author Fabien Potencier <fabien@symfony.com>
  17.  */
  18. class ControllerResolver extends ContainerControllerResolver
  19. {
  20.     protected $parser;
  21.     public function __construct(ContainerInterface $containerControllerNameParser $parserLoggerInterface $logger null)
  22.     {
  23.         $this->parser $parser;
  24.         parent::__construct($container$logger);
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     protected function createController($controller)
  30.     {
  31.         if (false === strpos($controller'::') && === substr_count($controller':')) {
  32.             // controller in the a:b:c notation then
  33.             $controller $this->parser->parse($controller);
  34.         }
  35.         $resolvedController parent::createController($controller);
  36.         if (=== substr_count($controller':') && \is_array($resolvedController)) {
  37.             $resolvedController[0] = $this->configureController($resolvedController[0]);
  38.         }
  39.         return $resolvedController;
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     protected function instantiateController($class)
  45.     {
  46.         return $this->configureController(parent::instantiateController($class));
  47.     }
  48.     private function configureController($controller)
  49.     {
  50.         if ($controller instanceof ContainerAwareInterface) {
  51.             // @deprecated switch, to be removed in 4.0 where these classes
  52.             // won't implement ContainerAwareInterface anymore
  53.             switch (\get_class($controller)) {
  54.                 case RedirectController::class:
  55.                 case TemplateController::class:
  56.                     return $controller;
  57.             }
  58.             $controller->setContainer($this->container);
  59.         }
  60.         if ($controller instanceof AbstractController && null !== $previousContainer $controller->setContainer($this->container)) {
  61.             $controller->setContainer($previousContainer);
  62.         }
  63.         return $controller;
  64.     }
  65. }