Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit29dbb87

Browse files
committed
Support autowiring for EventDispatcher/EventDispatcherInterface
1 parent4eeb1f0 commit29dbb87

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
452452
// replace the regular event_dispatcher service with the debug one
453453
$definition =$container->findDefinition('event_dispatcher');
454454
$definition->setPublic(false);
455+
$definition->setAutowiringTypes([]);
455456
$container->setDefinition('debug.event_dispatcher.parent',$definition);
456457
$container->setAlias('event_dispatcher','debug.event_dispatcher');
457458
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<argumenttype="service"id="debug.event_dispatcher.parent" />
1515
<argumenttype="service"id="debug.stopwatch" />
1616
<argumenttype="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
<serviceid="debug.controller_resolver"decorates="controller_resolver"class="Symfony\Component\HttpKernel\Controller\TraceableControllerResolver">

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<services>
88
<serviceid="event_dispatcher"class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
99
<argumenttype="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
<serviceid="http_kernel"class="Symfony\Component\HttpKernel\HttpKernel">

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
useDoctrine\Common\Annotations\AnnotationReader;
1515
useDoctrine\Common\Annotations\CachedReader;
1616
useSymfony\Component\Templating\EngineInterfaceasComponentEngineInterface;
17+
useSymfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
18+
useSymfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
1719
useSymfony\Bundle\FrameworkBundle\Templating\EngineInterfaceasFrameworkBundleEngineInterface;
1820

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

51+
publicfunctiontestTraceableEventDispatcherAutowiring()
52+
{
53+
static::bootKernel(array('debug' =>true));
54+
$container =static::$kernel->getContainer();
55+
56+
$autowiredServices =$container->get('test.autowiring_types.autowired_services');
57+
$this->assertInstanceOf(TraceableEventDispatcher::class,$autowiredServices->getDispatcher());
58+
}
59+
60+
publicfunctiontestContainerAwareEventDispatcherAutowiring()
61+
{
62+
static::bootKernel(array('debug' =>false));
63+
$container =static::$kernel->getContainer();
64+
65+
$autowiredServices =$container->get('test.autowiring_types.autowired_services');
66+
$this->assertInstanceOf(ContainerAwareEventDispatcher::class,$autowiredServices->getDispatcher());
67+
}
68+
4969
protectedstaticfunctioncreateKernel(array$options =array())
5070
{
5171
returnparent::createKernel(array('test_case' =>'AutowiringTypes') +$options);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
useDoctrine\Common\Annotations\Reader;
1515
useSymfony\Bundle\FrameworkBundle\Templating\EngineInterfaceasFrameworkBundleEngineInterface;
1616
useSymfony\Component\Templating\EngineInterface;
17+
useSymfony\Component\EventDispatcher\EventDispatcherInterface;
1718

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

24-
publicfunction__construct(Reader$annotationReader =null,FrameworkBundleEngineInterface$frameworkBundleEngine,EngineInterface$engine)
26+
publicfunction__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
publicfunctiongetAnnotationReader()
@@ -42,4 +45,9 @@ public function getEngine()
4245
{
4346
return$this->engine;
4447
}
48+
49+
publicfunctiongetDispatcher()
50+
{
51+
return$this->dispatcher;
52+
}
4553
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp