-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Deprecation for event_dispatcher service is still triggered #23054
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
Comments
Thank god someone narrowed down the cause of this deprecation. I'd been getting it hundreds of times per request in a few projects after upgrading to Symfony I can confirm that the reproduction steps do cause the described deprecation. |
The problem comes from this pass, so on Show code@@ -2,8 +2,9 @@
namespace Knp\Bundle\PaginatorBundle\DependencyInjection\Compiler;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
class PaginatorConfigurationPass implements CompilerPassInterface
{
@@ -19,30 +20,6 @@
return;
}
- $definition = $container->findDefinition('event_dispatcher');
-
- foreach ($container->findTaggedServiceIds('knp_paginator.subscriber') as $id => $attributes) {
- // We must assume that the class value has been correctly filled, even if the service is created by a factory
- $class = $container->getDefinition($id)->getClass();
-
- $refClass = new \ReflectionClass($class);
- $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
- if (!$refClass->implementsInterface($interface)) {
- throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
- }
-
- foreach ($class::getSubscribedEvents() as $event => $options) {
- if (!is_array($options)) {
- $options = array($options, 0);
- }
- $definition->addMethodCall('addListenerService', array(
- $event,
- array($id, $options[0]),
- $options[1]
- ));
- }
- // sf 2.1.x only
- //$definition->addMethodCall('addSubscriberService', array($id, $class));
- }
+ (new RegisterListenersPass('event_dispatcher', 'knp_paginator.listener', 'knp_paginator.subscriber'))->process($container);
}
} Maybe you could have a look? (I can't do a PR right now) |
The PR proposed for KnpPaginatorBundle was merged and the deprecation warning disappeared. Thanks for your help @ogizanagi! |
As mentioned in #22223, it looks like the deprecation notice about ContainerAwareEventDispatcher is still emerging in some cases.
Step to reproduce:
create-project symfony/framework-standard-edition foo
cd foo
composer require knplabs/knp-paginator-bundle
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle()
inregisterBundles
ofAppKernel
Expected behavior: launching
bin/console server:run
and navigating tohttp://127.0.0.1:8000/
, no deprecations about ContainerAwareEventDispatcher should be triggered.Actual behavior: launching
bin/console server:run
and navigating tohttp://127.0.0.1:8000/
, I see in debug toolbar "User Deprecated: The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead."The relevant part of source code is in
var/cache/dev/appDevDebugProjectContainer.php
and it's followingThe text was updated successfully, but these errors were encountered: