Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba286de

Browse files
committed
Merge branch '2.14.x' into 3.0.x
* 2.14.x: PHPStan 1.8.11 (doctrine#10182) Add isMemberOf and isInstanceOf to Expr helper list (doctrine#10104) Migrate more references to annotations (doctrine#10176) Fix grammer in working-with-objects (doctrine#10120) Automap events in AttachEntityListenersListener (doctrine#10122) Adapt use statements to the code (doctrine#10174)
2 parents 31db15f + 1edfa91 commit ba286de

7 files changed

Lines changed: 44 additions & 9 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"require-dev": {
3939
"doctrine/coding-standard": "^10.0",
4040
"phpbench/phpbench": "^1.0",
41-
"phpstan/phpstan": "1.8.8",
41+
"phpstan/phpstan": "1.8.11",
4242
"phpunit/phpunit": "^9.5",
4343
"psr/log": "^1 || ^2 || ^3",
4444
"squizlabs/php_codesniffer": "3.7.1",

docs/en/reference/query-builder.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ complete list of supported helper methods available:
434434
// Example - $qb->expr()->isNotNull('u.id') => u.id IS NOT NULL
435435
public function isNotNull($x); // Returns string
436436
437+
// Example - $qb->expr()->isMemberOf('?1', 'u.groups') => ?1 MEMBER OF u.groups
438+
public function isMemberOf($x, $y); // Returns Expr\Comparison instance
439+
440+
// Example - $qb->expr()->isInstanceOf('u', Employee::class) => u INSTANCE OF Employee
441+
public function isInstanceOf($x, $y); // Returns Expr\Comparison instance
442+
437443
438444
/** Arithmetic objects **/
439445

docs/en/reference/working-with-objects.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ as follows:
305305
- A removed entity X will be removed from the database as a result
306306
of the flush operation.
307307

308-
After an entity has been removed its in-memory state is the same as
308+
After an entity has been removed, its in-memory state is the same as
309309
before the removal, except for generated identifiers.
310310

311311
Removing an entity will also automatically delete any existing

docs/en/tutorials/ordered-associations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The DQL Snippet in OrderBy is only allowed to consist of
4343
unqualified, unquoted field names and of an optional ASC/DESC
4444
positional statement. Multiple Fields are separated by a comma (,).
4545
The referenced field names have to exist on the ``targetEntity``
46-
class of the ``#[ManyToMany]`` or ``#[OneToMany]`` annotation.
46+
class of the ``#[ManyToMany]`` or ``#[OneToMany]`` attribute.
4747

4848
The semantics of this feature can be described as follows:
4949

lib/Doctrine/ORM/Events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function __construct()
8282

8383
/**
8484
* The loadClassMetadata event occurs after the mapping metadata for a class
85-
* has been loaded from a mapping source (annotations/xml).
85+
* has been loaded from a mapping source (attributes/xml).
8686
*/
8787
public const loadClassMetadata = 'loadClassMetadata';
8888

lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ORM\Tools;
66

77
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
8+
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder;
89

910
use function ltrim;
1011

@@ -17,18 +18,18 @@ class AttachEntityListenersListener
1718
private array $entityListeners = [];
1819

1920
/**
20-
* Adds a entity listener for a specific entity.
21+
* Adds an entity listener for a specific entity.
2122
*
2223
* @param string $entityClass The entity to attach the listener.
2324
* @param string $listenerClass The listener class.
24-
* @param string $eventName The entity lifecycle event.
25+
* @param string|null $eventName The entity lifecycle event.
2526
* @param string|null $listenerCallback The listener callback method or NULL to use $eventName.
2627
*/
2728
public function addEntityListener(
2829
string $entityClass,
2930
string $listenerClass,
30-
string $eventName,
31-
$listenerCallback = null,
31+
string|null $eventName = null,
32+
string|null $listenerCallback = null,
3233
): void {
3334
$this->entityListeners[ltrim($entityClass, '\\')][] = [
3435
'event' => $eventName,
@@ -49,7 +50,11 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
4950
}
5051

5152
foreach ($this->entityListeners[$metadata->name] as $listener) {
52-
$metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']);
53+
if ($listener['event'] === null) {
54+
EntityListenerBuilder::bindEntityListener($metadata, $listener['class']);
55+
} else {
56+
$metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']);
57+
}
5358
}
5459

5560
unset($this->entityListeners[$metadata->name]);

tests/Doctrine/Tests/ORM/Tools/AttachEntityListenersListenerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ public function testDuplicateEntityListenerException(): void
110110

111111
$this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class);
112112
}
113+
114+
public function testAttachWithoutSpecifyingAnEventName(): void
115+
{
116+
$this->listener->addEntityListener(
117+
AttachEntityListenersListenerTestFooEntity::class,
118+
AttachEntityListenersListenerTestListener::class,
119+
);
120+
121+
$metadata = $this->factory->getMetadataFor(AttachEntityListenersListenerTestFooEntity::class);
122+
123+
self::assertCount(2, $metadata->entityListeners);
124+
125+
self::assertArrayHasKey('prePersist', $metadata->entityListeners);
126+
self::assertArrayHasKey('postPersist', $metadata->entityListeners);
127+
128+
self::assertCount(1, $metadata->entityListeners['prePersist']);
129+
self::assertCount(1, $metadata->entityListeners['postPersist']);
130+
131+
self::assertEquals('prePersist', $metadata->entityListeners['prePersist'][0]['method']);
132+
self::assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['prePersist'][0]['class']);
133+
134+
self::assertEquals('postPersist', $metadata->entityListeners['postPersist'][0]['method']);
135+
self::assertEquals(AttachEntityListenersListenerTestListener::class, $metadata->entityListeners['postPersist'][0]['class']);
136+
}
113137
}
114138

115139
#[Entity]

0 commit comments

Comments
 (0)