[DI] Dont trigger deprecation for event_dispatcher service
This commit is contained in:
parent
329b1819f1
commit
a49fe25fa3
@ -31,6 +31,7 @@ use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
||||
use Symfony\Component\Serializer\Serializer;
|
||||
@ -878,6 +879,18 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
$this->assertTrue($container->has('property_info'));
|
||||
}
|
||||
|
||||
public function testEventDispatcherService()
|
||||
{
|
||||
$container = $this->createContainer(array('kernel.charset' => 'UTF-8', 'kernel.secret' => 'secret'));
|
||||
$container->registerExtension(new FrameworkExtension());
|
||||
$this->loadFromFile($container, 'default_config');
|
||||
$container
|
||||
->register('foo', \stdClass::class)
|
||||
->setProperty('dispatcher', new Reference('event_dispatcher'));
|
||||
$container->compile();
|
||||
$this->assertInstanceOf(EventDispatcherInterface::class, $container->get('foo')->dispatcher);
|
||||
}
|
||||
|
||||
public function testCacheDefaultRedisProvider()
|
||||
{
|
||||
$container = $this->createContainerFromFile('cache');
|
||||
|
@ -38,6 +38,7 @@ use Symfony\Component\Config\Resource\ResourceInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
@ -1056,11 +1057,14 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));
|
||||
$r = new \ReflectionClass($class = $parameterBag->resolveValue($definition->getClass()));
|
||||
|
||||
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
|
||||
// don't trigger deprecations for internal uses
|
||||
// @deprecated since version 3.3, to be removed in 4.0 along with the deprecated class
|
||||
$deprecationWhitelist = array('event_dispatcher' => ContainerAwareEventDispatcher::class);
|
||||
|
||||
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
|
||||
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ") && (!isset($deprecationWhitelist[$id]) || $deprecationWhitelist[$id] !== $class)) {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user