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

Skip to content

[DI] Dont trigger deprecation for event_dispatcher service #22223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -878,6 +879,18 @@ public function testPropertyInfoEnabled()
$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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;

Expand Down Expand Up @@ -1056,11 +1057,14 @@ private function createService(Definition $definition, $id, $tryProxy = true)
}
}
} 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);
}
}
Expand Down