diff --git a/ContainerAwareEventManager.php b/ContainerAwareEventManager.php index b0b5c0f4..6c66812f 100644 --- a/ContainerAwareEventManager.php +++ b/ContainerAwareEventManager.php @@ -207,8 +207,8 @@ private function initializeSubscribers(): void if (\is_string($listener)) { $listener = $this->container->get($listener); } - // throw new \InvalidArgumentException(sprintf('Using Doctrine subscriber "%s" is not allowed, declare it as a listener instead.', \is_object($listener) ? $listener::class : $listener)); - trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener); + // throw new \InvalidArgumentException(sprintf('Using Doctrine subscriber "%s" is not allowed. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.', \is_object($listener) ? $listener::class : $listener)); + trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.', \is_object($listener) ? get_debug_type($listener) : $listener); parent::addEventSubscriber($listener); } } diff --git a/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php b/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php index bf35a95e..d920fbcc 100644 --- a/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php +++ b/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php @@ -106,7 +106,7 @@ private function addTaggedServices(ContainerBuilder $container): array $refs = $managerDef->getArguments()[1] ?? []; $listenerRefs[$con][$id] = new Reference($id); if ($subscriberTag === $tagName) { - trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.', $id); + trigger_deprecation('symfony/doctrine-bridge', '6.3', 'Registering "%s" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[%s] attribute.', $id, str_starts_with($this->tagPrefix, 'doctrine_mongodb') ? 'AsDocumentListener' : 'AsDoctrineListener'); $refs[] = $id; } else { $refs[] = [[$tag['event']], $id]; diff --git a/Tests/ContainerAwareEventManagerTest.php b/Tests/ContainerAwareEventManagerTest.php index ec8930c7..88315b51 100644 --- a/Tests/ContainerAwareEventManagerTest.php +++ b/Tests/ContainerAwareEventManagerTest.php @@ -50,7 +50,7 @@ public function testDispatchEventRespectOrderWithSubscribers() $this->container->set('sub1', $subscriber1 = new MySubscriber(['foo'])); $this->container->set('sub2', $subscriber2 = new MySubscriber(['foo'])); - $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.'); + $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.'); $this->assertSame([$subscriber1, $subscriber2], array_values($this->evm->getListeners('foo'))); } @@ -92,7 +92,7 @@ public function testDispatchEventWithSubscribers() $this->assertSame(0, $subscriber1->calledSubscribedEventsCount); $this->container->set('lazy1', $listener1 = new MyListener()); - $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.'); + $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.'); $this->evm->addEventListener('foo', 'lazy1'); $this->evm->addEventListener('foo', $listener2 = new MyListener()); $this->evm->addEventSubscriber($subscriber2 = new MySubscriber(['bar'])); @@ -177,7 +177,7 @@ public function testAddEventListenerAndSubscriberAfterDispatchEvent() $this->assertSame(0, $subscriber1->calledSubscribedEventsCount); $this->container->set('lazy1', $listener1 = new MyListener()); - $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.'); + $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.'); $this->evm->addEventListener('foo', 'lazy1'); $this->assertSame(1, $subscriber1->calledSubscribedEventsCount); @@ -238,7 +238,7 @@ public function testGetListenersForEventWhenSubscribersArePresent() $this->container->set('lazy', $listener1 = new MyListener()); $this->container->set('lazy2', $subscriber1 = new MySubscriber(['foo'])); - $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] attribute.'); + $this->expectDeprecation('Since symfony/doctrine-bridge 6.3: Registering "Symfony\Bridge\Doctrine\Tests\MySubscriber" as a Doctrine subscriber is deprecated. Register it as a listener instead, using e.g. the #[AsDoctrineListener] or #[AsDocumentListener] attribute.'); $this->evm->addEventListener('foo', 'lazy'); $this->evm->addEventListener('foo', $listener2 = new MyListener());