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 22, 2023
1 parent 49bfb83 commit 7aa4332
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions Attribute/AsDocumentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Attribute;

use function trigger_deprecation;

/**
* Service tag to autoconfigure document listeners.
*/
Expand All @@ -14,10 +16,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) {
trigger_deprecation(
'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 32 in Attribute/AsDocumentListener.php

View check run for this annotation

Codecov / codecov/patch

Attribute/AsDocumentListener.php#L28-L32

Added lines #L28 - L32 were not covered by tests
}

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

Check warning on line 40 in Attribute/AsDocumentListener.php

View check run for this annotation

Codecov / codecov/patch

Attribute/AsDocumentListener.php#L36-L40

Added lines #L36 - L40 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',
'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 7aa4332

Please sign in to comment.