설명 없음

RegisterLocaleAwareServicesPass.php 1.7KB

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