Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61f3922

Browse files
committed
[DI] Dont trigger deprecation for event_dispatcher service
1 parent 329b181 commit 61f3922

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
3232
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
3333
use Symfony\Component\DependencyInjection\Reference;
34+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3435
use Symfony\Component\PropertyAccess\PropertyAccessor;
3536
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
3637
use Symfony\Component\Serializer\Serializer;
@@ -878,6 +879,18 @@ public function testPropertyInfoEnabled()
878879
$this->assertTrue($container->has('property_info'));
879880
}
880881

882+
public function testEventDispatcherService()
883+
{
884+
$container = $this->createContainer(array('kernel.charset' => 'UTF-8', 'kernel.secret' => 'secret'));
885+
$container->registerExtension(new FrameworkExtension());
886+
$this->loadFromFile($container, 'default_config');
887+
$container
888+
->register('foo', \stdClass::class)
889+
->setProperty('dispatcher', new Reference('event_dispatcher'));
890+
$container->compile();
891+
$this->assertInstanceOf(EventDispatcherInterface::class, $container->get('foo')->dispatcher);
892+
}
893+
881894
public function testCacheDefaultRedisProvider()
882895
{
883896
$container = $this->createContainerFromFile('cache');

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
3939
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
4040
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
41+
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
4142
use Symfony\Component\ExpressionLanguage\Expression;
4243
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
4344

@@ -1056,11 +1057,13 @@ private function createService(Definition $definition, $id, $tryProxy = true)
10561057
}
10571058
}
10581059
} else {
1059-
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));
1060+
$r = new \ReflectionClass($class = $parameterBag->resolveValue($definition->getClass()));
10601061

10611062
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
1063+
// don't trigger deprecations for internal uses, to be removed in 4.0 along with the deprecated class
1064+
$deprecationWhitelist = array('event_dispatcher' => ContainerAwareEventDispatcher::class);
10621065

1063-
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
1066+
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ") && (!isset($deprecationWhitelist[$id]) || $deprecationWhitelist[$id] !== $class)) {
10641067
@trigger_error(sprintf('The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name), E_USER_DEPRECATED);
10651068
}
10661069
}

0 commit comments

Comments
 (0)