-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow using Enum from different namespace than Entity #9384
Conversation
@@ -1517,7 +1517,7 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array | |||
! isset($mapping['type']) | |||
&& ($type instanceof ReflectionNamedType) | |||
) { | |||
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName(), false)) { | |||
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why autoload was disabled in the first place. @beberlei , do you remember?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triggering the autoloader here is correct. We cannot be certain at this point that the property type has been autoloaded already.
However, this has nothig little to do with the namespace we place the enum in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, I've checked this before writing it: with disabled autoloading Enum from the Entity namespace is somehow visible, that's why unit tests working with Enums\TypedCard
are green. But moving Enum to another namespace break things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can confirm we need removing false
. Works for me now.
@@ -1517,7 +1517,7 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array | |||
! isset($mapping['type']) | |||
&& ($type instanceof ReflectionNamedType) | |||
) { | |||
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName(), false)) { | |||
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triggering the autoloader here is correct. We cannot be certain at this point that the property type has been autoloaded already.
However, this has nothig little to do with the namespace we place the enum in.
So do I need to write some test for this or is the fix enough obvious? It's hard to write autoloading tests, because there is no guarantee that someone else doesn't loaded your class already. |
Fix is obvious |
* 2.12.x: Allow using Enum from different namespace than Entity (doctrine#9384) Corrected ORM version and added missing dependency (doctrine#9386) PHPStan 1.4.0 (doctrine#9385) [doctrineGH-9380] Bugfix: Delegate ReflectionEnumProperty::getAttributes(). (doctrine#9381) Support enum cases as parameters (doctrine#9373) Add detach as of list cascade-all operations (doctrine#9357)
Allows using Enums from different namespace than Entity, for example,
App\DBAL\Enum
andApp\Entity
.Without this fix it works only when both Enum and Entity are placed in the same namespace like
App\Entity
, and nobody is responsible for autoloading these Enums.