Nenhuma descrição

AddEventAliasesPass.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\EventDispatcher\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. /**
  14. * This pass allows bundles to extend the list of event aliases.
  15. *
  16. * @author Alexander M. Turek <me@derrabus.de>
  17. */
  18. class AddEventAliasesPass implements CompilerPassInterface
  19. {
  20. private $eventAliases;
  21. private $eventAliasesParameter;
  22. public function __construct(array $eventAliases, string $eventAliasesParameter = 'event_dispatcher.event_aliases')
  23. {
  24. $this->eventAliases = $eventAliases;
  25. $this->eventAliasesParameter = $eventAliasesParameter;
  26. }
  27. public function process(ContainerBuilder $container): void
  28. {
  29. $eventAliases = $container->hasParameter($this->eventAliasesParameter) ? $container->getParameter($this->eventAliasesParameter) : [];
  30. $container->setParameter(
  31. $this->eventAliasesParameter,
  32. array_merge($eventAliases, $this->eventAliases)
  33. );
  34. }
  35. }