RegisterLocaleAwareServicesPass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /**
  23. * @return void
  24. */
  25. public function process(ContainerBuilder $container)
  26. {
  27. if (!$container->hasDefinition('locale_aware_listener')) {
  28. return;
  29. }
  30. $services = [];
  31. foreach ($container->findTaggedServiceIds('kernel.locale_aware') as $id => $tags) {
  32. $services[] = new Reference($id);
  33. }
  34. if (!$services) {
  35. $container->removeDefinition('locale_aware_listener');
  36. return;
  37. }
  38. $container
  39. ->getDefinition('locale_aware_listener')
  40. ->setArgument(0, new IteratorArgument($services))
  41. ;
  42. }
  43. }