Comments (6)
Version 3.1.0 of doctrine-laminas-hydrator has just been released!
from doctrine-laminas-hydrator.
Thanks for reporting this issue. Indeed, such hydration is not handled properly, mostly because backed enum typed properties are a rather new feature of Doctrine. Could you please provide a PR including the fix and relevant test cases based on the 2.2.x branch? I'll be happy to review and merge your PR in the 2.2 and 3.0 series.
from doctrine-laminas-hydrator.
This is a common issue in the hydrator library, we have the same issue for isNullable
:
doctrine-laminas-hydrator/src/DoctrineObject.php
Lines 726 to 742 in a1c99f4
Here isNullable()
is only present in Doctrine\ORM\Mapping\ClassMetadata
(inherited from Doctrine\ORM\Mapping\ClassMetadataInfo
), but not in Doctrine\Persistence\Mapping\ClassMetadata
. Same for getAssociationMapping()
.
I would suggest using a similar approach for getFieldMapping()
.
from doctrine-laminas-hydrator.
I have been looking into adding enum support on the side too (unofficially of course - having been playing around with 8.1's enums and Doctrine's new enum and attribute support).
Unless I am mistaken, @ezkimo I do not think your suggestion will work for hydration?
My understanding is that to accomplish hydration for enums we would need access to the ClassMetadataInfo::getFieldMapping()
method to be able to determine the enumType
from the attributes/annotations of the field itself, at least in the case of a non-typed setters and properties.
Unfortunately, this method is not defined on the ClassMetadata
interface in Doctrine/Persistence
, only in the concrete implementation in Doctrine/ORM
(and some but not all the ODM packages!) and as such would need to be added upstream in Doctrine/Persistence
. I am uncertain whether doing this would be a breaking change or not.
An alternative option could be to use Reflection to get the enum class name and use BackedEnum::tryFrom()
, but this would enforce the use of typed setters and properties (for both by-reference and by-value hydration) to be used in the target Entity. This is not a terrible thing IMO.
from doctrine-laminas-hydrator.
It looks like this would work, but would be untestable due to PHPUnit rightfully not allowing us to mock getFieldMapping
on Doctrine\Persistence\Mapping\ClassMetadata
.
I think @ezkimo solution of requiring a Strategy for each enum be implemented coupled with something like the below to DoctrineObject::hydrateValue
could be a solution (note: returning the enum instead of enum->value
here as previously proposed)
if (interface_exists('BackedEnum') && $value instanceof BackedEnum) {
return $value;
}
The only other option would be the previously use of Reflection, which would only work by ignoring any attributes/annotations and trusting the entity has the correctly typed property/setter on the entity class.
from doctrine-laminas-hydrator.
Since Enums have never been supported till now, we will consider this a new feature and bring it into the upcoming 3.1.0 release. However, we will need someone to write a few notes for the docs (see #57, #59).
from doctrine-laminas-hydrator.
Related Issues (17)
- Hydrating uploaded image array to entity HOT 2
- Deprecation notices from doctrine\common HOT 1
- DoctrineObject extractByReference on uninitialized variables (PHP 7.4) HOT 3
- README documentation links to zend framework HOT 1
- Issue with unassigned members / PHP 7.4 (Typed property must not be accessed before initialization) HOT 2
- Wrong case of decimal and bigint HOT 2
- Problem with file uploads HOT 10
- Proof-reading of documentation HOT 2
- Removal of identifier values in toMany() function HOT 9
- Documentation issues and hydration apparently not working for Embeddable HOT 5
- Collection nested collection HOT 2
- Add support for time_immutable and date_immutable
- Problem with the compare function of the AbstractCollectionStrategy HOT 6
- Association extraction HOT 1
- Hydrator is trying to update instead of replace collection entities - can this be prevented? HOT 1
- hydrate composite PK HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from doctrine-laminas-hydrator.