Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b366aa1

Browse filesBrowse files
committed
feature #21625 Remove some container injections in favor of service locators (nicolas-grekas, chalasr)
This PR was merged into the 3.3-dev branch. Discussion ---------- Remove some container injections in favor of service locators | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#21553 (comment) | License | MIT | Doc PR | n/a Commits ------- 8293b753cf Replace some container injections by service locators 0be9ea8ba1 [EventDispatcher] Fix abstract event subscribers registration
2 parents e01281a + 44b713f commit b366aa1
Copy full SHA for b366aa1

File tree

1 file changed

+13
-3
lines changed
Filter options

1 file changed

+13
-3
lines changed

‎DependencyInjection/RegisterListenersPass.php

Copy file name to clipboardExpand all lines: DependencyInjection/RegisterListenersPass.php
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\EventDispatcher\EventDispatcher;
19+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1920

2021
/**
2122
* Compiler pass to register tagged services for an event dispatcher.
@@ -105,8 +106,8 @@ public function process(ContainerBuilder $container)
105106
}
106107
$container->addObjectResource($class);
107108

108-
$r = new \ReflectionClass($class);
109-
$extractingDispatcher->addSubscriber($r->newInstanceWithoutConstructor());
109+
ExtractingEventDispatcher::$subscriber = $class;
110+
$extractingDispatcher->addSubscriber($extractingDispatcher);
110111
foreach ($extractingDispatcher->listeners as $args) {
111112
$args[1] = new ClosureProxyArgument($id, $args[1]);
112113
$definition->addMethodCall('addListener', $args);
@@ -119,12 +120,21 @@ public function process(ContainerBuilder $container)
119120
/**
120121
* @internal
121122
*/
122-
class ExtractingEventDispatcher extends EventDispatcher
123+
class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
123124
{
124125
public $listeners = array();
125126

127+
public static $subscriber;
128+
126129
public function addListener($eventName, $listener, $priority = 0)
127130
{
128131
$this->listeners[] = array($eventName, $listener[1], $priority);
129132
}
133+
134+
public static function getSubscribedEvents()
135+
{
136+
$callback = array(self::$subscriber, 'getSubscribedEvents');
137+
138+
return $callback();
139+
}
130140
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.