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\ContainerInterface;
  13. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  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.             if ($resolvedController[0] instanceof ContainerAwareInterface) {
  38.                 $resolvedController[0]->setContainer($this->container);
  39.             }
  40.             if ($resolvedController[0] instanceof AbstractController && null !== $previousContainer $resolvedController[0]->setContainer($this->container)) {
  41.                 $resolvedController[0]->setContainer($previousContainer);
  42.             }
  43.         }
  44.         return $resolvedController;
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     protected function instantiateController($class)
  50.     {
  51.         $controller parent::instantiateController($class);
  52.         if ($controller instanceof ContainerAwareInterface) {
  53.             $controller->setContainer($this->container);
  54.         }
  55.         if ($controller instanceof AbstractController && null !== $previousContainer $controller->setContainer($this->container)) {
  56.             $controller->setContainer($previousContainer);
  57.         }
  58.         return $controller;
  59.     }
  60. }