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 6bec2f0 commit a6dae81
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,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.',
);

Check warning on line 30 in Attribute/AsDocumentListener.php

View check run for this annotation

Codecov / codecov/patch

Attribute/AsDocumentListener.php#L26-L30

Added lines #L26 - L30 were not covered by tests
}

if ($lazy !== null) {
Deprecation::trigger(
'doctrine/mongodb-odm-bundle',
'4.7',
'Lazy loading is not supported.',
);

Check warning on line 38 in Attribute/AsDocumentListener.php

View check run for this annotation

Codecov / codecov/patch

Attribute/AsDocumentListener.php#L34-L38

Added lines #L34 - L38 were not covered by tests
}
}
}
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',
],
], $listenerDefinition->getTag('doctrine_mongodb.odm.event_listener'));
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')]
#[AsDocumentListener(event: 'prePersist', connection: 'test')]
class TestAttributeListener
{
public function onPrePersist(): void
public function prePersist(): void
{
}
}

0 comments on commit a6dae81

Please sign in to comment.