From a5553a07869cab5cef2536e96e346f4dbd7bc740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 25 Oct 2022 23:25:36 +0200 Subject: [PATCH 1/6] Adapt use statements to the code (#10174) --- docs/en/reference/advanced-configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/advanced-configuration.rst b/docs/en/reference/advanced-configuration.rst index 943046995fd..a27d277ff37 100644 --- a/docs/en/reference/advanced-configuration.rst +++ b/docs/en/reference/advanced-configuration.rst @@ -130,7 +130,7 @@ The attribute driver can be injected in the ``Doctrine\ORM\Configuration``: .. code-block:: php setMetadataDriverImpl($driverImpl); From c828a3814b410871c935efe7913d8114f7ab2204 Mon Sep 17 00:00:00 2001 From: HypeMC <2445045+HypeMC@users.noreply.github.com> Date: Wed, 26 Oct 2022 10:36:06 +0200 Subject: [PATCH 2/6] Automap events in AttachEntityListenersListener (#10122) --- .../Tools/AttachEntityListenersListener.php | 11 +++++--- .../AttachEntityListenersListenerTest.php | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php index d1657367eef..8b3e7977ad4 100644 --- a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php +++ b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php @@ -5,6 +5,7 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; +use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; use function ltrim; @@ -17,11 +18,11 @@ class AttachEntityListenersListener private $entityListeners = []; /** - * Adds a entity listener for a specific entity. + * Adds an entity listener for a specific entity. * * @param string $entityClass The entity to attach the listener. * @param string $listenerClass The listener class. - * @param string $eventName The entity lifecycle event. + * @param string|null $eventName The entity lifecycle event. * @param string|null $listenerCallback The listener callback method or NULL to use $eventName. * * @return void @@ -49,7 +50,11 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event) } foreach ($this->entityListeners[$metadata->name] as $listener) { - $metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']); + if ($listener['event'] === null) { + EntityListenerBuilder::bindEntityListener($metadata, $listener['class']); + } else { + $metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']); + } } unset($this->entityListeners[$metadata->name]); diff --git a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php index e26d072212f..485794e331a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php @@ -112,6 +112,31 @@ public function testDuplicateEntityListenerException(): void $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class); } + + public function testAttachWithoutSpecifyingAnEventName(): void + { + $this->listener->addEntityListener( + AttachEntityListenersListenerTestFooEntity::class, + AttachEntityListenersListenerTestListener::class, + null + ); + + $metadata = $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class); + + self::assertCount(2, $metadata->entityListeners); + + self::assertArrayHasKey('prePersist', $metadata->entityListeners); + self::assertArrayHasKey('postPersist', $metadata->entityListeners); + + self::assertCount(1, $metadata->entityListeners['prePersist']); + self::assertCount(1, $metadata->entityListeners['postPersist']); + + self::assertEquals('prePersist', $metadata->entityListeners['prePersist'][0]['method']); + self::assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['prePersist'][0]['class']); + + self::assertEquals('postPersist', $metadata->entityListeners['postPersist'][0]['method']); + self::assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['postPersist'][0]['class']); + } } /** @Entity */ From bb1deba510605b900d5e514527431c7b561d4696 Mon Sep 17 00:00:00 2001 From: Jonny Eom Date: Wed, 26 Oct 2022 04:39:05 -0400 Subject: [PATCH 3/6] Fix grammer in working-with-objects (#10120) --- docs/en/reference/working-with-objects.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 5bc272f4664..203367039df 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -305,7 +305,7 @@ as follows: - A removed entity X will be removed from the database as a result of the flush operation. -After an entity has been removed its in-memory state is the same as +After an entity has been removed, its in-memory state is the same as before the removal, except for generated identifiers. Removing an entity will also automatically delete any existing From 7cf4074d3a493ad882d1fef23e8019a07f77c51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 26 Oct 2022 10:42:42 +0200 Subject: [PATCH 4/6] Migrate more references to annotations (#10176) --- docs/en/tutorials/ordered-associations.rst | 2 +- lib/Doctrine/ORM/Events.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/tutorials/ordered-associations.rst b/docs/en/tutorials/ordered-associations.rst index 4a5183e19f8..9e414e0680e 100644 --- a/docs/en/tutorials/ordered-associations.rst +++ b/docs/en/tutorials/ordered-associations.rst @@ -76,7 +76,7 @@ The DQL Snippet in OrderBy is only allowed to consist of unqualified, unquoted field names and of an optional ASC/DESC positional statement. Multiple Fields are separated by a comma (,). The referenced field names have to exist on the ``targetEntity`` -class of the ``#[ManyToMany]`` or ``#[OneToMany]`` annotation. +class of the ``#[ManyToMany]`` or ``#[OneToMany]`` attribute. The semantics of this feature can be described as follows: diff --git a/lib/Doctrine/ORM/Events.php b/lib/Doctrine/ORM/Events.php index d2339e97f81..e23093fccce 100644 --- a/lib/Doctrine/ORM/Events.php +++ b/lib/Doctrine/ORM/Events.php @@ -82,7 +82,7 @@ private function __construct() /** * The loadClassMetadata event occurs after the mapping metadata for a class - * has been loaded from a mapping source (annotations/xml/yaml). + * has been loaded from a mapping source (attributes/xml/yaml). */ public const loadClassMetadata = 'loadClassMetadata'; From 3133bf06c2a18559e09cd7487ef89fdd70d0fd24 Mon Sep 17 00:00:00 2001 From: Romain Monteil Date: Wed, 26 Oct 2022 11:04:17 +0200 Subject: [PATCH 5/6] Add isMemberOf and isInstanceOf to Expr helper list (#10104) * Add isMemberOf and isInstanceOf to Expr helper list * Apply suggestions from code review Co-authored-by: Alexander M. Turek --- docs/en/reference/query-builder.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 50a1b8dc73c..7e3e3fff363 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -434,6 +434,12 @@ complete list of supported helper methods available: // Example - $qb->expr()->isNotNull('u.id') => u.id IS NOT NULL public function isNotNull($x); // Returns string + // Example - $qb->expr()->isMemberOf('?1', 'u.groups') => ?1 MEMBER OF u.groups + public function isMemberOf($x, $y); // Returns Expr\Comparison instance + + // Example - $qb->expr()->isInstanceOf('u', Employee::class) => u INSTANCE OF Employee + public function isInstanceOf($x, $y); // Returns Expr\Comparison instance + /** Arithmetic objects **/ From 75e42abfdfb1059101f47823059bf51f90405ecc Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 26 Oct 2022 11:36:22 +0200 Subject: [PATCH 6/6] PHPStan 1.8.11 (#10182) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 187bd907ef9..2d1b724eb4c 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "doctrine/annotations": "^1.13", "doctrine/coding-standard": "^9.0.2 || ^10.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.8.8", + "phpstan/phpstan": "~1.4.10 || 1.8.11", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.1",