diff --git a/Attribute/AsDocumentListener.php b/Attribute/AsDocumentListener.php index 0c73e8ce..6d888adc 100644 --- a/Attribute/AsDocumentListener.php +++ b/Attribute/AsDocumentListener.php @@ -5,6 +5,7 @@ namespace Doctrine\Bundle\MongoDBBundle\Attribute; use Attribute; +use Doctrine\Deprecations\Deprecation; /** * Service tag to autoconfigure document listeners. @@ -14,9 +15,27 @@ class AsDocumentListener { public function __construct( public ?string $event = null, + /** @deprecated the method name is the same as the event name */ public ?string $method = null, + /** @deprecated not supported */ public ?bool $lazy = null, public ?string $connection = null, ) { + // phpcs:disable SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed + if ($method !== null) { + Deprecation::trigger( + 'doctrine/mongodb-odm-bundle', + '4.7', + 'The method name is the same as the event name, so it can be omitted.', + ); + } + + if ($lazy !== null) { + Deprecation::trigger( + 'doctrine/mongodb-odm-bundle', + '4.7', + 'Lazy loading is not supported.', + ); + } } } diff --git a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php index fbe69742..4b828f55 100644 --- a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php @@ -94,8 +94,8 @@ public function testAsDocumentListenerAttribute(): void self::assertSame([ [ 'event' => 'prePersist', - 'method' => 'onPrePersist', - 'lazy' => true, + 'method' => null, + 'lazy' => null, 'connection' => 'test', ], ], $listenerDefinition->getTag('doctrine_mongodb.odm.event_listener')); diff --git a/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/EventListener/TestAttributeListener.php b/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/EventListener/TestAttributeListener.php index b0b1935b..eeea2e1e 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/EventListener/TestAttributeListener.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/EventListener/TestAttributeListener.php @@ -6,10 +6,10 @@ use Doctrine\Bundle\MongoDBBundle\Attribute\AsDocumentListener; -#[AsDocumentListener(event: 'prePersist', method: 'onPrePersist', lazy: true, connection: 'test')] +#[AsDocumentListener(event: 'prePersist', connection: 'test')] class TestAttributeListener { - public function onPrePersist(): void + public function prePersist(): void { } }