From e62571c8f40c56797137d491067fc573b28739fe Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 2 Mar 2024 23:11:11 +0100 Subject: [PATCH 1/2] Refator array_map into simple loop for performance. (#11332) --- src/UnitOfWork.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 00698e56c60..0ccbb8ead5f 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -1781,18 +1781,15 @@ public function addToIdentityMap($entity) */ final public static function getIdHashByIdentifier(array $identifier): string { + foreach ($identifier as $k => $value) { + if ($value instanceof BackedEnum) { + $identifier[$k] = $value->value; + } + } + return implode( ' ', - array_map( - static function ($value) { - if ($value instanceof BackedEnum) { - return $value->value; - } - - return $value; - }, - $identifier - ) + $identifier ); } From ba0ea8953beba94d4fa71207bcc4803d2f96d11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 3 Mar 2024 13:08:37 +0100 Subject: [PATCH 2/2] Use class from persistence package (#11330) * Use class from persistence package It is meant to remove duplication between the ORM and the ODM. * Update UPGRADE.md Co-authored-by: Steve Todd --------- Co-authored-by: Alexander M. Turek Co-authored-by: Steve Todd --- UPGRADE.md | 6 ++++++ composer.json | 2 +- src/Mapping/ClassMetadata.php | 5 +++-- src/Mapping/ReflectionEmbeddedProperty.php | 2 +- src/Mapping/ReflectionEnumProperty.php | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 3dd84679ed2..01020b90a9a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,11 @@ # Upgrade to 3.1 +## Deprecate `Doctrine\ORM\Mapping\ReflectionEnumProperty` + +This class is deprecated and will be removed in 4.0. +Instead, use `Doctrine\Persistence\Reflection\EnumReflectionProperty` from +`doctrine/persistence`. + ## Deprecate passing null to `ClassMetadata::fullyQualifiedClassName()` Passing `null` to `Doctrine\ORM\ClassMetadata::fullyQualifiedClassName()` is diff --git a/composer.json b/composer.json index e435f8addc2..1a42c2c3ab8 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "doctrine/inflector": "^1.4 || ^2.0", "doctrine/instantiator": "^1.3 || ^2", "doctrine/lexer": "^3", - "doctrine/persistence": "^3.1.1", + "doctrine/persistence": "^3.3.1", "psr/cache": "^1 || ^2 || ^3", "symfony/console": "^5.4 || ^6.0 || ^7.0", "symfony/var-exporter": "~6.2.13 || ^6.3.2 || ^7.0" diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index fd547e92589..85079ed049d 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -15,6 +15,7 @@ use Doctrine\ORM\Id\AbstractIdGenerator; use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata; use Doctrine\Persistence\Mapping\ReflectionService; +use Doctrine\Persistence\Reflection\EnumReflectionProperty; use InvalidArgumentException; use LogicException; use ReflectionClass; @@ -822,7 +823,7 @@ public function wakeupReflection(ReflectionService $reflService): void assert($childProperty !== null); if (isset($mapping->enumType)) { - $childProperty = new ReflectionEnumProperty( + $childProperty = new EnumReflectionProperty( $childProperty, $mapping->enumType, ); @@ -841,7 +842,7 @@ public function wakeupReflection(ReflectionService $reflService): void : $this->getAccessibleProperty($reflService, $this->name, $field); if (isset($mapping->enumType) && $this->reflFields[$field] !== null) { - $this->reflFields[$field] = new ReflectionEnumProperty( + $this->reflFields[$field] = new EnumReflectionProperty( $this->reflFields[$field], $mapping->enumType, ); diff --git a/src/Mapping/ReflectionEmbeddedProperty.php b/src/Mapping/ReflectionEmbeddedProperty.php index 6f818f89773..da3d09749b4 100644 --- a/src/Mapping/ReflectionEmbeddedProperty.php +++ b/src/Mapping/ReflectionEmbeddedProperty.php @@ -30,7 +30,7 @@ public function __construct( private readonly ReflectionProperty $childProperty, private readonly string $embeddedClass, ) { - parent::__construct($childProperty->class, $childProperty->name); + parent::__construct($childProperty->getDeclaringClass()->name, $childProperty->getName()); } public function getValue(object|null $object = null): mixed diff --git a/src/Mapping/ReflectionEnumProperty.php b/src/Mapping/ReflectionEnumProperty.php index 9b4ff0e8f34..0ebd978f412 100644 --- a/src/Mapping/ReflectionEnumProperty.php +++ b/src/Mapping/ReflectionEnumProperty.php @@ -11,6 +11,7 @@ use function array_map; use function is_array; +/** @deprecated use Doctrine\Persistence\Reflection\EnumReflectionProperty instead */ final class ReflectionEnumProperty extends ReflectionProperty { /** @param class-string $enumType */