From 70b8b162463af72667672575d59e02b939634399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Schlu=CC=88ter?= Date: Fri, 21 May 2021 12:04:35 +0200 Subject: [PATCH] [EventDispatcher] Removed deprecated code --- .../AddEventAliasesPass.php | 12 ++----- .../RegisterListenersPass.php | 33 +++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php index 6e7292b4a189e..b77811b38b17c 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php @@ -22,24 +22,18 @@ class AddEventAliasesPass implements CompilerPassInterface { private $eventAliases; - private $eventAliasesParameter; - public function __construct(array $eventAliases, string $eventAliasesParameter = 'event_dispatcher.event_aliases') + public function __construct(array $eventAliases) { - if (1 < \func_num_args()) { - trigger_deprecation('symfony/event-dispatcher', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); - } - $this->eventAliases = $eventAliases; - $this->eventAliasesParameter = $eventAliasesParameter; } public function process(ContainerBuilder $container): void { - $eventAliases = $container->hasParameter($this->eventAliasesParameter) ? $container->getParameter($this->eventAliasesParameter) : []; + $eventAliases = $container->hasParameter('event_dispatcher.event_aliases') ? $container->getParameter('event_dispatcher.event_aliases') : []; $container->setParameter( - $this->eventAliasesParameter, + 'event_dispatcher.event_aliases', array_merge($eventAliases, $this->eventAliases) ); } diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 8d8d567bc027d..8a8d65c1c9632 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -25,28 +25,11 @@ */ class RegisterListenersPass implements CompilerPassInterface { - protected $dispatcherService; - protected $listenerTag; - protected $subscriberTag; - protected $eventAliasesParameter; - private $hotPathEvents = []; private $hotPathTagName; private $noPreloadEvents = []; private $noPreloadTagName; - public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber', string $eventAliasesParameter = 'event_dispatcher.event_aliases') - { - if (0 < \func_num_args()) { - trigger_deprecation('symfony/event-dispatcher', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); - } - - $this->dispatcherService = $dispatcherService; - $this->listenerTag = $listenerTag; - $this->subscriberTag = $subscriberTag; - $this->eventAliasesParameter = $eventAliasesParameter; - } - /** * @return $this */ @@ -71,26 +54,26 @@ public function setNoPreloadEvents(array $noPreloadEvents, string $tagName = 'co public function process(ContainerBuilder $container) { - if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) { + if (!$container->hasDefinition('event_dispatcher') && !$container->hasAlias('event_dispatcher')) { return; } $aliases = []; - if ($container->hasParameter($this->eventAliasesParameter)) { - $aliases = $container->getParameter($this->eventAliasesParameter); + if ($container->hasParameter('event_dispatcher.event_aliases')) { + $aliases = $container->getParameter('event_dispatcher.event_aliases'); } - $globalDispatcherDefinition = $container->findDefinition($this->dispatcherService); + $globalDispatcherDefinition = $container->findDefinition('event_dispatcher'); - foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) { + foreach ($container->findTaggedServiceIds('kernel.event_listener', true) as $id => $events) { $noPreload = 0; foreach ($events as $event) { $priority = $event['priority'] ?? 0; if (!isset($event['event'])) { - if ($container->getDefinition($id)->hasTag($this->subscriberTag)) { + if ($container->getDefinition($id)->hasTag('kernel.event_subscriber')) { continue; } @@ -133,7 +116,7 @@ public function process(ContainerBuilder $container) $extractingDispatcher = new ExtractingEventDispatcher(); - foreach ($container->findTaggedServiceIds($this->subscriberTag, true) as $id => $tags) { + foreach ($container->findTaggedServiceIds('kernel.event_subscriber', true) as $id => $tags) { $def = $container->getDefinition($id); // We must assume that the class value has been correctly filled, even if the service is created by a factory @@ -195,7 +178,7 @@ private function getEventFromTypeDeclaration(ContainerBuilder $container, string || $type->isBuiltin() || Event::class === ($name = $type->getName()) ) { - throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag)); + throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); } return $name;