vendor\symfony\framework-bundle\Controller\ControllerResolver.php line 62

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.  * @final since Symfony 4.4
  19.  */
  20. class ControllerResolver extends ContainerControllerResolver
  21. {
  22.     /**
  23.      * @deprecated since Symfony 4.4
  24.      */
  25.     protected $parser;
  26.     /**
  27.      * @param LoggerInterface|null $logger
  28.      */
  29.     public function __construct(ContainerInterface $container, $logger = null)
  30.     {
  31.         if ($logger instanceof ControllerNameParser) {
  32.             @trigger_error(sprintf('Passing a "%s" instance as 2nd argument to "%s()" is deprecated since Symfony 4.4, pass a "%s" instance or null instead.', ControllerNameParser::class, __METHOD__, LoggerInterface::class), \E_USER_DEPRECATED);
  33.             $this->parser = $logger;
  34.             $logger = 2 < \func_num_args() ? func_get_arg(2) : null;
  35.         } elseif (2 < \func_num_args() && func_get_arg(2) instanceof ControllerNameParser) {
  36.             $this->parser = func_get_arg(2);
  37.         } elseif ($logger && !$logger instanceof LoggerInterface) {
  38.             throw new \TypeError(sprintf('Argument 2 of "%s()" must be an instance of "%s" or null, "%s" given.', __METHOD__, LoggerInterface::class, \is_object($logger) ? \get_class($logger) : \gettype($logger)), \E_USER_DEPRECATED);
  39.         }
  40.         parent::__construct($container, $logger);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     protected function createController($controller)
  46.     {
  47.         if ($this->parser && !str_contains($controller, '::') && 2 === substr_count($controller, ':')) {
  48.             // controller in the a:b:c notation then
  49.             $deprecatedNotation = $controller;
  50.             $controller = $this->parser->parse($deprecatedNotation, false);
  51.             @trigger_error(sprintf('Referencing controllers with %s is deprecated since Symfony 4.1. Use %s instead.', $deprecatedNotation, $controller), \E_USER_DEPRECATED);
  52.         }
  53.         return parent::createController($controller);
  54.     }
  55.     /**
  56.      * {@inheritdoc}
  57.      */
  58.     protected function instantiateController($class)
  59.     {
  60.         $controller = parent::instantiateController($class);
  61.         if ($controller instanceof ContainerAwareInterface) {
  62.             $controller->setContainer($this->container);
  63.         }
  64.         if ($controller instanceof AbstractController) {
  65.             if (null === $previousContainer = $controller->setContainer($this->container)) {
  66.                 @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);
  67.             // To be uncommented on Symfony 5:
  68.                 //throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
  69.             } else {
  70.                 $controller->setContainer($previousContainer);
  71.             }
  72.         }
  73.         return $controller;
  74.     }
  75. }