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 d2d68dd

Browse filesBrowse files
committed
Support autowiring for EventDispatcher/EventDispatcherInterface
CS Fixes
1 parent a559036 commit d2d68dd
Copy full SHA for d2d68dd

File tree

5 files changed

+34
-8
lines changed
Filter options

5 files changed

+34
-8
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,8 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
449449
if ($debug) {
450450
$loader->load('debug.xml');
451451

452-
// replace the regular event_dispatcher service with the debug one
453-
$definition = $container->findDefinition('event_dispatcher');
454-
$definition->setPublic(false);
455-
$container->setDefinition('debug.event_dispatcher.parent', $definition);
456-
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
452+
// autowire services using the debug.event_dispatcher service instead of event_dispatcher
453+
$container->findDefinition('event_dispatcher')->setAutowiringTypes(array());
457454
}
458455

459456
$definition = $container->findDefinition('debug.debug_handlers_listener');

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
</parameters>
1010

1111
<services>
12-
<service id="debug.event_dispatcher" class="Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher">
12+
<service id="debug.event_dispatcher" class="Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher" decorates="event_dispatcher">
1313
<tag name="monolog.logger" channel="event" />
14-
<argument type="service" id="debug.event_dispatcher.parent" />
14+
<argument type="service" id="debug.event_dispatcher.inner" />
1515
<argument type="service" id="debug.stopwatch" />
1616
<argument type="service" id="logger" on-invalid="null" />
17+
<autowiring-type>Symfony\Component\EventDispatcher\EventDispatcherInterface</autowiring-type>
18+
<autowiring-type>Symfony\Component\EventDispatcher\EventDispatcher</autowiring-type>
1719
</service>
1820

1921
<service id="debug.controller_resolver" decorates="controller_resolver" class="Symfony\Component\HttpKernel\Controller\TraceableControllerResolver">

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<services>
88
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
99
<argument type="service" id="service_container" />
10+
<autowiring-type>Symfony\Component\EventDispatcher\EventDispatcherInterface</autowiring-type>
11+
<autowiring-type>Symfony\Component\EventDispatcher\EventDispatcher</autowiring-type>
1012
</service>
1113

1214
<service id="http_kernel" class="Symfony\Component\HttpKernel\HttpKernel">

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\CachedReader;
1616
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
17+
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
18+
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
1719
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
1820

1921
class AutowiringTypesTest extends WebTestCase
@@ -46,6 +48,21 @@ public function testTemplatingAutowiring()
4648
$this->assertInstanceOf(ComponentEngineInterface::class, $autowiredServices->getEngine());
4749
}
4850

51+
public function testEventDispatcherAutowiring()
52+
{
53+
static::bootKernel(array('debug' => false));
54+
$container = static::$kernel->getContainer();
55+
56+
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
57+
$this->assertInstanceOf(ContainerAwareEventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled');
58+
59+
static::bootKernel(array('debug' => true));
60+
$container = static::$kernel->getContainer();
61+
62+
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
63+
$this->assertInstanceOf(TraceableEventDispatcher::class, $autowiredServices->getDispatcher(), 'The debug.event_dispatcher service should be injected if the debug is enabled');
64+
}
65+
4966
protected static function createKernel(array $options = array())
5067
{
5168
return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
use Doctrine\Common\Annotations\Reader;
1515
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
1616
use Symfony\Component\Templating\EngineInterface;
17+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1718

1819
class AutowiredServices
1920
{
2021
private $annotationReader;
2122
private $frameworkBundleEngine;
2223
private $engine;
24+
private $dispatcher;
2325

24-
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine)
26+
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine, EventDispatcherInterface $dispatcher)
2527
{
2628
$this->annotationReader = $annotationReader;
2729
$this->frameworkBundleEngine = $frameworkBundleEngine;
2830
$this->engine = $engine;
31+
$this->dispatcher = $dispatcher;
2932
}
3033

3134
public function getAnnotationReader()
@@ -42,4 +45,9 @@ public function getEngine()
4245
{
4346
return $this->engine;
4447
}
48+
49+
public function getDispatcher()
50+
{
51+
return $this->dispatcher;
52+
}
4553
}

0 commit comments

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