Skip to content

Commit

Permalink
Deprecate AsDocumentListener::$method and $lazy (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Dec 21, 2023
1 parent 49bfb83 commit b5b1a3c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
19 changes: 19 additions & 0 deletions Attribute/AsDocumentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Bundle\MongoDBBundle\Attribute;

use Attribute;
use Doctrine\Deprecations\Deprecation;

/**
* Service tag to autoconfigure document listeners.
Expand All @@ -14,10 +15,28 @@ 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,
public ?int $priority = 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.',
);
}
}
}
4 changes: 2 additions & 2 deletions Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public function testAsDocumentListenerAttribute(): void
self::assertSame([
[
'event' => 'prePersist',
'method' => 'onPrePersist',
'lazy' => true,
'method' => null,
'lazy' => null,
'connection' => 'test',
'priority' => 10,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Doctrine\Bundle\MongoDBBundle\Attribute\AsDocumentListener;

#[AsDocumentListener(event: 'prePersist', method: 'onPrePersist', lazy: true, connection: 'test', priority: 10)]
#[AsDocumentListener(event: 'prePersist', connection: 'test', priority: 10)]
class TestAttributeListener
{
public function onPrePersist(): void
public function prePersist(): void
{
}
}

0 comments on commit b5b1a3c

Please sign in to comment.