Skip to content

Commit 53847a8

Browse files
wouterjfabpot
authored andcommitted
[Security] Refactor logout listener to dispatch an event instead
1 parent d972711 commit 53847a8

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* The `LegacyEventDispatcherProxy` class has been deprecated.
8+
* Added an optional `dispatcher` attribute to the listener and subscriber tags in `RegisterListenerPass`.
89

910
5.0.0
1011
-----

DependencyInjection/RegisterListenersPass.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function process(ContainerBuilder $container)
6161
} else {
6262
$aliases = [];
6363
}
64-
$definition = $container->findDefinition($this->dispatcherService);
64+
$globalDispatcherDefinition = $container->findDefinition($this->dispatcherService);
6565

6666
foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
6767
foreach ($events as $event) {
@@ -90,7 +90,12 @@ public function process(ContainerBuilder $container)
9090
}
9191
}
9292

93-
$definition->addMethodCall('addListener', [$event['event'], [new ServiceClosureArgument(new Reference($id)), $event['method']], $priority]);
93+
$dispatcherDefinition = $globalDispatcherDefinition;
94+
if (isset($event['dispatcher'])) {
95+
$dispatcherDefinition = $container->getDefinition($event['dispatcher']);
96+
}
97+
98+
$dispatcherDefinition->addMethodCall('addListener', [$event['event'], [new ServiceClosureArgument(new Reference($id)), $event['method']], $priority]);
9499

95100
if (isset($this->hotPathEvents[$event['event']])) {
96101
$container->getDefinition($id)->addTag($this->hotPathTagName);
@@ -100,7 +105,7 @@ public function process(ContainerBuilder $container)
100105

101106
$extractingDispatcher = new ExtractingEventDispatcher();
102107

103-
foreach ($container->findTaggedServiceIds($this->subscriberTag, true) as $id => $attributes) {
108+
foreach ($container->findTaggedServiceIds($this->subscriberTag, true) as $id => $tags) {
104109
$def = $container->getDefinition($id);
105110

106111
// We must assume that the class value has been correctly filled, even if the service is created by a factory
@@ -114,12 +119,27 @@ public function process(ContainerBuilder $container)
114119
}
115120
$class = $r->name;
116121

122+
$dispatcherDefinitions = [];
123+
foreach ($tags as $attributes) {
124+
if (!isset($attributes['dispatcher']) || isset($dispatcherDefinitions[$attributes['dispatcher']])) {
125+
continue;
126+
}
127+
128+
$dispatcherDefinitions[] = $container->getDefinition($attributes['dispatcher']);
129+
}
130+
131+
if ([] === $dispatcherDefinitions) {
132+
$dispatcherDefinitions = [$globalDispatcherDefinition];
133+
}
134+
117135
ExtractingEventDispatcher::$aliases = $aliases;
118136
ExtractingEventDispatcher::$subscriber = $class;
119137
$extractingDispatcher->addSubscriber($extractingDispatcher);
120138
foreach ($extractingDispatcher->listeners as $args) {
121139
$args[1] = [new ServiceClosureArgument(new Reference($id)), $args[1]];
122-
$definition->addMethodCall('addListener', $args);
140+
foreach ($dispatcherDefinitions as $dispatcherDefinition) {
141+
$dispatcherDefinition->addMethodCall('addListener', $args);
142+
}
123143

124144
if (isset($this->hotPathEvents[$args[0]])) {
125145
$container->getDefinition($id)->addTag($this->hotPathTagName);

0 commit comments

Comments
 (0)