You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

3 years ago
  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. if (1 < \func_num_args()) {
  25. trigger_deprecation('symfony/event-dispatcher', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
  26. }
  27. $this->eventAliases = $eventAliases;
  28. $this->eventAliasesParameter = $eventAliasesParameter;
  29. }
  30. public function process(ContainerBuilder $container): void
  31. {
  32. $eventAliases = $container->hasParameter($this->eventAliasesParameter) ? $container->getParameter($this->eventAliasesParameter) : [];
  33. $container->setParameter(
  34. $this->eventAliasesParameter,
  35. array_merge($eventAliases, $this->eventAliases)
  36. );
  37. }
  38. }