From b7c76f7147249e33508467917b07fd470585ee9f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 21 May 2017 09:51:07 +0200 Subject: [PATCH] [FrameworkBundle] FC with EventDispatcher 4.0 --- .../DependencyInjection/FrameworkExtension.php | 9 +++++++++ .../Tests/Functional/AutowiringTypesTest.php | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index c65c1f8e74..993bae7f4a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -32,6 +32,8 @@ use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; +use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Finder\Finder; @@ -94,6 +96,13 @@ class FrameworkExtension extends Extension $loader->load('web.xml'); $loader->load('services.xml'); + // forward compatibility with Symfony 4.0 where the ContainerAwareEventDispatcher class is removed + if (!class_exists(ContainerAwareEventDispatcher::class)) { + $definition = $container->getDefinition('event_dispatcher'); + $definition->setClass(EventDispatcher::class); + $definition->setArguments(array()); + } + if (PHP_VERSION_ID < 70000) { $definition = $container->getDefinition('kernel.class_cache.cache_warmer'); $definition->addTag('kernel.cache_warmer'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php index fa92514a9c..057a522fb3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\CachedReader; use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface; use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher; use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; @@ -55,7 +56,12 @@ class AutowiringTypesTest extends WebTestCase $container = static::$kernel->getContainer(); $autowiredServices = $container->get('test.autowiring_types.autowired_services'); - $this->assertInstanceOf(ContainerAwareEventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled'); + + if (class_exists(ContainerAwareEventDispatcher::class)) { + $this->assertInstanceOf(ContainerAwareEventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled'); + } else { + $this->assertInstanceOf(EventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled'); + } static::bootKernel(array('debug' => true)); $container = static::$kernel->getContainer();