bug #22223 [DI] Dont trigger deprecation for event_dispatcher service (chalasr)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Dont trigger deprecation for event_dispatcher service
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #22208
| License | MIT
| Doc PR | n/a
Mute deprecations for the event_dispatcher service keeping only relevant ones i.e when the api of the deprecated class is used intentionally, ugly but prevent breaking test suites like the [LexikJWTAuthenticationBundle one](https://travis-ci.org/lexik/LexikJWTAuthenticationBundle/jobs/216664013#L278).
Commits
-------
a49fe25fa3
[DI] Dont trigger deprecation for event_dispatcher service
This commit is contained in:
commit
88c587df78
@ -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