Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReflectionEnumProperty::getValue() return the enum #10131

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/Id/AssignedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Id;

use BackedEnum;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\EntityMissingAssignedId;

Expand Down Expand Up @@ -39,6 +40,10 @@ public function generateId(EntityManagerInterface $em, $entity)
$value = $em->getUnitOfWork()->getSingleIdentifierValue($value);
}

if ($value instanceof BackedEnum) {
$value = $value->value;
}

$identifier[$idField] = $value;
}

Expand Down
10 changes: 2 additions & 8 deletions lib/Doctrine/ORM/Mapping/ReflectionEnumProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(ReflectionProperty $originalReflectionProperty, stri
*
* @param object|null $object
*
* @return int|string|int[]|string[]|null
* @return BackedEnum|null
*/
#[ReturnTypeWillChange]
public function getValue($object = null)
Expand All @@ -53,13 +53,7 @@ public function getValue($object = null)
return null;
}

if (is_array($enum)) {
return array_map(static function (BackedEnum $item): mixed {
return $item->value;
}, $enum);
}

return $enum->value;
return $enum;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ protected function prepareUpdateData($entity, bool $isInsert = false)
}

$newVal = $change[1];
if ($newVal instanceof BackedEnum) {
$newVal = $newVal->value;
}

if (! isset($this->class->associationMappings[$field])) {
$fieldMapping = $this->class->fieldMappings[$field];
Expand Down