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

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.             $deprecatedNotation $controller;
  34.             $controller $this->parser->parse($deprecatedNotationfalse);
  35.             @trigger_error(sprintf('Referencing controllers with %s is deprecated since Symfony 4.1. Use %s instead.'$deprecatedNotation$controller), E_USER_DEPRECATED);
  36.         }
  37.         return parent::createController($controller);
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     protected function instantiateController($class)
  43.     {
  44.         return $this->configureController(parent::instantiateController($class), $class);
  45.     }
  46.     private function configureController($controllerstring $class)
  47.     {
  48.         if ($controller instanceof ContainerAwareInterface) {
  49.             $controller->setContainer($this->container);
  50.         }
  51.         if ($controller instanceof AbstractController) {
  52.             if (null === $previousContainer $controller->setContainer($this->container)) {
  53.                 @trigger_error(sprintf('Auto-injection of the container for "%s" is deprecated since Symfony 4.2. Configure it as a service instead.'$class), E_USER_DEPRECATED);
  54.             // To be uncommented on Symfony 5:
  55.                 //throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
  56.             } else {
  57.                 $controller->setContainer($previousContainer);
  58.             }
  59.         }
  60.         return $controller;
  61.     }
  62. }