-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
FEATURE: Create ValueObjects from simple types by calling from$TYPE
for objects and JsonArray properties
#2762
FEATURE: Create ValueObjects from simple types by calling from$TYPE
for objects and JsonArray properties
#2762
Conversation
from$TYPE
for objects and JsonArray properties
@albe @bwaidelich @mhsdesign as you commented on the original pr and already liked it just not as a bugfix. |
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.
Looks good, left a "naming question".
Neos.Flow/Classes/Property/TypeConverter/DenormalizingObjectConverter.php
Outdated
Show resolved
Hide resolved
to be in line with the type annotations used in php code.
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.
😘
Approval by reading…
One last question: Do you think this would deserve some documentation? Or should we rely on generated type converter reference?
@kdambekalns docs would be great but i am not entirely sure where to put what. Can be done later imho. |
Found and fixed the issues psalm detected. All green now. |
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.
Still looks good to me :)
…previous takes precedence This should avoid problems when flow entities implement JsonSerializable. In this case we would like to serialize as an entity.
@kdambekalns @nezaniel pushed a final adjustment to handle the value object serialization in JsonArray after the check for flow-objects. That should avoid problems wit flow entities that implement JsonSerializable. |
After chat with @nezaniel we agreed that the last change makes sense and improves confidence. Will merge with the existing reviews as this is a minor cosmetic change. |
Oh no, I was one hour too late.. |
@bwaidelich can you decide on this with @kdambekalns i am really not that opinionated on this and until we push release we can still adjust this. To me the argument to use the same syntax as in typeAnnotations made more sense. |
i guess there is no right or wrong way - but if we decided to took road |
OK, I'll try to rephrase my arguments for the full version. IMO...
In the end it probably boils down to preference. If you guys agree to my suggestion, I'm happy to create a follow-up PR with adjustments (and provide some documentation on the way). |
@bwaidelich you had me at "and provide some documentation on the way" Not entirely sure about supporting long and short versions but that might be the friendliest way in the end. |
Thinking further i would prefer to add the additional methods as a last minute feature. If we do not get this intuitively noone else will. |
No, it does not… not anymore than for anything else. And I find it unfortunate that PHP now uses both ways, but not in all places. 🤷♂️
I repeat my argument about the short form being more "universal" in the PHP context. We do support But I didn't know about the same methods used in the EventSourcing package already, and I do see value in both ways. So… whatever. 🙃 |
I agree to what Martin said - having both ways supported is probably the most friendly way to handle this in the core. I do not see any drawbacks from that, since there are no subtle differences in using one or the other. It's just there to remove mental load from developers, which is good. Let's do this @bwaidelich |
There you go: #2766 |
With neos/flow-development-collection#2762 native support for vo's in various places was introduced. Also in node property values where the neos ui uses the `DenormalizingObjectConverter` to convert the serialized data to the object. Unfortunately the reverse currently does NOT use the expected `\JsonSerializable::jsonSerialize` but rather asks the `ArrayFromObjectConverter` for object types when serializing properties for the ui. That leads to the need of aop like here https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 This bugfix will make use of the `\JsonSerializable` interface instead directly when serializing properties for the neos ui.
With neos/flow-development-collection#2762 native support for vo's in various places was introduced. Also in node property values where the neos ui uses the `DenormalizingObjectConverter` to convert the serialized data to the object. Unfortunately the reverse currently does NOT use the expected `\JsonSerializable::jsonSerialize` but rather asks the `ArrayFromObjectConverter` for object types when serializing properties for the ui. That leads to the need of aop like here https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 This bugfix will make use of the `\JsonSerializable` interface instead directly when serializing properties for the neos ui.
With neos/flow-development-collection#2762 native support for vo's in various places was introduced. Also in node property values where the neos ui uses the `DenormalizingObjectConverter` to convert the serialized data to the object. Unfortunately the reverse currently does NOT use the expected `\JsonSerializable::jsonSerialize` but rather asks the `ArrayFromObjectConverter` for object types when serializing properties for the ui. That leads to the need of aop like here https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 This bugfix will make use of the `\JsonSerializable` interface instead directly when serializing properties for the neos ui.
With neos/flow-development-collection#2762 native support for vo's in various places was introduced. Also in node property values where the neos ui uses the `DenormalizingObjectConverter` to convert the serialized data to the object. Unfortunately the reverse currently does NOT use the expected `\JsonSerializable::jsonSerialize` but rather asks the `ArrayFromObjectConverter` for object types when serializing properties for the ui. That leads to the need of aop like here https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 This bugfix will make use of the `\JsonSerializable` interface instead directly when serializing properties for the neos ui.
With neos/flow-development-collection#2762 native support for vo's in various places was introduced. Also in node property values where the neos ui uses the `DenormalizingObjectConverter` to convert the serialized data to the object. Unfortunately the reverse currently does NOT use the expected `\JsonSerializable::jsonSerialize` but rather asks the `ArrayFromObjectConverter` for object types when serializing properties for the ui. That leads to the need of aop like here https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 This bugfix will make use of the `\JsonSerializable` interface instead directly when serializing properties for the neos ui.
With neos/flow-development-collection#2762 native support for vo's in various places was introduced. Also in node property values where the neos ui uses the `DenormalizingObjectConverter` to convert the serialized data to the object. Unfortunately the reverse currently does NOT use the expected `\JsonSerializable::jsonSerialize` but rather asks the `ArrayFromObjectConverter` for object types when serializing properties for the ui. That leads to the need of aop like here https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 This bugfix will make use of the `\JsonSerializable` interface instead directly when serializing properties for the neos ui.
…d directly when serializing properties for the neos ui. With neos/flow-development-collection#2762 native support for vo's in `flow_json_array` was introduced. That also allows value object support for node properties, as they can be stored directly the node properties flow_json_array. Unfortunately the property serialisation for the NeosUi does NOT use the expected `\JsonSerializable::jsonSerialize` but the property mapper and the `ArrayFromObjectConverter` for object types to get an array that will be json encoded. This works mostly fine but in some cases it fails: - when your `fromArray` fields and property names values dont match - when a "object" subtypes the object mapper is no convertable like the `GuzzleHttp\Psr7\Uri`: ``` Too few arguments to function GuzzleHttp\Psr7\Uri::isAbsolute(), 0 passed in /core/neos-manufacture-highest/Packages/Framework/Neos.Utility.ObjectHandling/Classes/ObjectAccess.php on line 151 and exactly 1 expected ``` Current workarounds are aop: https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 Or to use a dumb property mapper: https://github.com/sitegeist/Sitegeist.Archaeopteryx/blob/9322b9cb8e4824bcaf7aaa247c23b1244a2f1167/Classes/LinkToArrayForNeosUiConverter.php#L12C16-L12C78
This bugfix will make use of the \JsonSerializable interface instead directly when serializing properties for the neos ui. With neos/flow-development-collection#2762 native support for vo's in `flow_json_array` was introduced. That also allows value object support for node properties, as they can be stored directly the node properties flow_json_array. Unfortunately the property serialisation for the NeosUi does NOT use the expected `\JsonSerializable::jsonSerialize` but the property mapper and the `ArrayFromObjectConverter` for object types to get an array that will be json encoded. This works mostly fine but in some cases it fails: - when your `fromArray` fields and property names values dont match - when a "object" subtypes the object mapper is no convertable like the `GuzzleHttp\Psr7\Uri`: ``` Too few arguments to function GuzzleHttp\Psr7\Uri::isAbsolute(), 0 passed in /core/neos-manufacture-highest/Packages/Framework/Neos.Utility.ObjectHandling/Classes/ObjectAccess.php on line 151 and exactly 1 expected ``` Current workarounds are aop: https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 Or to use a dumb property mapper: https://github.com/sitegeist/Sitegeist.Archaeopteryx/blob/9322b9cb8e4824bcaf7aaa247c23b1244a2f1167/Classes/LinkToArrayForNeosUiConverter.php#L12C16-L12C78
This bugfix will make use of the \JsonSerializable interface instead directly when serializing properties for the neos ui. With neos/flow-development-collection#2762 native support for vo's in `flow_json_array` was introduced. That also allows value object support for node properties, as they can be stored directly the node properties flow_json_array. Unfortunately the property serialisation for the NeosUi does NOT use the expected `\JsonSerializable::jsonSerialize` but the property mapper and the `ArrayFromObjectConverter` for object types to get an array that will be json encoded. This works mostly fine but in some cases it fails: - when your `fromArray` fields and property names values dont match - when a "object" subtypes the object mapper is no convertable like the `GuzzleHttp\Psr7\Uri`: ``` Too few arguments to function GuzzleHttp\Psr7\Uri::isAbsolute(), 0 passed in /core/neos-manufacture-highest/Packages/Framework/Neos.Utility.ObjectHandling/Classes/ObjectAccess.php on line 151 and exactly 1 expected ``` Current workarounds are aop: https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 Or to use a dumb property mapper: https://github.com/sitegeist/Sitegeist.Archaeopteryx/blob/9322b9cb8e4824bcaf7aaa247c23b1244a2f1167/Classes/LinkToArrayForNeosUiConverter.php#L12C16-L12C78
This bugfix will make use of the \JsonSerializable interface instead directly when serializing properties for the neos ui. With neos/flow-development-collection#2762 native support for vo's in `flow_json_array` was introduced. That also allows value object support for node properties, as they can be stored directly the node properties flow_json_array. Unfortunately the property serialisation for the NeosUi does NOT use the expected `\JsonSerializable::jsonSerialize` but the property mapper and the `ArrayFromObjectConverter` for object types to get an array that will be json encoded. This works mostly fine but in some cases it fails: - when your `fromArray` fields and property names values dont match - when a "object" subtypes the object mapper is no convertable like the `GuzzleHttp\Psr7\Uri`: ``` Too few arguments to function GuzzleHttp\Psr7\Uri::isAbsolute(), 0 passed in /core/neos-manufacture-highest/Packages/Framework/Neos.Utility.ObjectHandling/Classes/ObjectAccess.php on line 151 and exactly 1 expected ``` Current workarounds are aop: https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 Or to use a dumb property mapper: https://github.com/sitegeist/Sitegeist.Archaeopteryx/blob/9322b9cb8e4824bcaf7aaa247c23b1244a2f1167/Classes/LinkToArrayForNeosUiConverter.php#L12C16-L12C78
Ports neos/neos-development-collection#4638 to the Neos Ui, as the class was moved in Neos 9. Original commit message: This bugfix will make use of the \JsonSerializable interface instead directly when serializing properties for the neos ui. With neos/flow-development-collection#2762 native support for vo's in `flow_json_array` was introduced. That also allows value object support for node properties, as they can be stored directly the node properties flow_json_array. Unfortunately the property serialisation for the NeosUi does NOT use the expected `\JsonSerializable::jsonSerialize` but the property mapper and the `ArrayFromObjectConverter` for object types to get an array that will be json encoded. This works mostly fine but in some cases it fails: - when your `fromArray` fields and property names values dont match - when a "object" subtypes the object mapper is no convertable like the `GuzzleHttp\Psr7\Uri`: ``` Too few arguments to function GuzzleHttp\Psr7\Uri::isAbsolute(), 0 passed in /core/neos-manufacture-highest/Packages/Framework/Neos.Utility.ObjectHandling/Classes/ObjectAccess.php on line 151 and exactly 1 expected ``` Current workarounds are aop: https://github.com/sitegeist/Sitegeist.InspectorGadget/blob/78f5f4a206287b1c4bedf5cb88582ed51cb4a311/Classes/Infrastructure/NodeInfo/NodeInfoPostProcessingAspect.php#L17 Or to use a dumb property mapper: https://github.com/sitegeist/Sitegeist.Archaeopteryx/blob/9322b9cb8e4824bcaf7aaa247c23b1244a2f1167/Classes/LinkToArrayForNeosUiConverter.php#L12C16-L12C78
When converting from simple types the denormalizer now checks wether the target class has a method
from$TYPE
and uses this to create the object. Supported method names arefromArray
,fromString
,fromBool
,fromInt
andfromFloat
.For example the following controller action would use the methods
BirthDate::fromString
orBirthDate::fromArray
(depending on submitted data) to instantiate the $birthDate argument.In addition the JsonArray Type is extended to support this aswell. The serialization as flow entities takes precedence over the serialization as value object flow objects that implement \JsonSerializable are still serialized as Flow Objects in JsonArray properties. While beeing a Flow feature this allows to store and restore ValueObjects in Neos Node properties aswell.
Note: This is a rebased version of #2703 from @nezaniel
Resolves: #2763
Replaces: #2703
Checklist