Skip to content

Commit b7c76f7

Browse files
committed
[FrameworkBundle] FC with EventDispatcher 4.0
1 parent e9e19e7 commit b7c76f7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3333
use Symfony\Component\DependencyInjection\Reference;
3434
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
35+
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
36+
use Symfony\Component\EventDispatcher\EventDispatcher;
3537
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
3638
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
3739
use Symfony\Component\Finder\Finder;
@@ -94,6 +96,13 @@ public function load(array $configs, ContainerBuilder $container)
9496
$loader->load('web.xml');
9597
$loader->load('services.xml');
9698

99+
// forward compatibility with Symfony 4.0 where the ContainerAwareEventDispatcher class is removed
100+
if (!class_exists(ContainerAwareEventDispatcher::class)) {
101+
$definition = $container->getDefinition('event_dispatcher');
102+
$definition->setClass(EventDispatcher::class);
103+
$definition->setArguments(array());
104+
}
105+
97106
if (PHP_VERSION_ID < 70000) {
98107
$definition = $container->getDefinition('kernel.class_cache.cache_warmer');
99108
$definition->addTag('kernel.cache_warmer');

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\CachedReader;
1616
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
17+
use Symfony\Component\EventDispatcher\EventDispatcher;
1718
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
1819
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
1920
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
@@ -55,7 +56,12 @@ public function testEventDispatcherAutowiring()
5556
$container = static::$kernel->getContainer();
5657

5758
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
58-
$this->assertInstanceOf(ContainerAwareEventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled');
59+
60+
if (class_exists(ContainerAwareEventDispatcher::class)) {
61+
$this->assertInstanceOf(ContainerAwareEventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled');
62+
} else {
63+
$this->assertInstanceOf(EventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled');
64+
}
5965

6066
static::bootKernel(array('debug' => true));
6167
$container = static::$kernel->getContainer();

0 commit comments

Comments
 (0)