Skip to content

Commit

Permalink
Merge branch '2.14.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
derrabus committed Oct 26, 2022
2 parents 31db15f + 1edfa91 commit f2b62a2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -38,7 +38,7 @@
"require-dev": {
"doctrine/coding-standard": "^10.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.8.8",
"phpstan/phpstan": "1.8.11",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
Expand Down
6 changes: 6 additions & 0 deletions docs/en/reference/query-builder.rst
Expand Up @@ -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 **/
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/working-with-objects.rst
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/en/tutorials/ordered-associations.rst
Expand Up @@ -43,7 +43,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:

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Events.php
Expand Up @@ -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).
* has been loaded from a mapping source (attributes/xml).
*/
public const loadClassMetadata = 'loadClassMetadata';

Expand Down
15 changes: 10 additions & 5 deletions lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Tools;

use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder;

use function ltrim;

Expand All @@ -17,18 +18,18 @@ class AttachEntityListenersListener
private array $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.
*/
public function addEntityListener(
string $entityClass,
string $listenerClass,
string $eventName,
$listenerCallback = null,
string|null $eventName = null,
string|null $listenerCallback = null,
): void {
$this->entityListeners[ltrim($entityClass, '\\')][] = [
'event' => $eventName,
Expand All @@ -49,7 +50,11 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
}

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]);
Expand Down
Expand Up @@ -110,6 +110,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]
Expand Down

0 comments on commit f2b62a2

Please sign in to comment.