RegisterLocaleAwareServicesPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\HttpKernel\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * Register all services that have the "kernel.locale_aware" tag into the listener.
  17. *
  18. * @author Pierre Bobiet <pierrebobiet@gmail.com>
  19. */
  20. class RegisterLocaleAwareServicesPass implements CompilerPassInterface
  21. {
  22. public function process(ContainerBuilder $container): void
  23. {
  24. if (!$container->hasDefinition('locale_aware_listener')) {
  25. return;
  26. }
  27. $services = [];
  28. foreach ($container->findTaggedServiceIds('kernel.locale_aware') as $id => $tags) {
  29. $services[] = new Reference($id);
  30. }
  31. if (!$services) {
  32. $container->removeDefinition('locale_aware_listener');
  33. return;
  34. }
  35. $container
  36. ->getDefinition('locale_aware_listener')
  37. ->setArgument(0, new IteratorArgument($services))
  38. ;
  39. }
  40. }