RoutingControllerPass.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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\Component\Routing\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. /**
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. final class RoutingControllerPass implements CompilerPassInterface
  18. {
  19. use PriorityTaggedServiceTrait;
  20. public function process(ContainerBuilder $container): void
  21. {
  22. if (!$container->hasDefinition('routing.loader.attribute.services')) {
  23. return;
  24. }
  25. $resolve = $container->getParameterBag()->resolveValue(...);
  26. $taggedClasses = [];
  27. foreach ($this->findAndSortTaggedServices('routing.controller', $container) as $id) {
  28. $taggedClasses[$resolve($container->getDefinition($id)->getClass())] = true;
  29. }
  30. $container->getDefinition('routing.loader.attribute.services')
  31. ->replaceArgument(0, array_keys($taggedClasses));
  32. }
  33. }