-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Union types deserialisation #1546
Union types deserialisation #1546
Conversation
Thanks for taking up this topic. Unfortunately I'm super short in time recently :( It looks like there was few issues found by the CI pipeline like:
Also, please use |
@scyzoryck I completely understand. I need union support for a project I'm working on, so I'm happy to push this forward. Thanks for taking the time to work with me. If you can kickoff the workflows again (I don't seem to be able to), I think I've fixed those issues. |
I will look into these phpstan issues tomorrow. |
Hey @scyzoryck I addressed the However, there were a number of phpstan related issues on a file that is not touched in this pull request: |
Hiya! I added a commit to only register the UnionHandler on PHPVersion > 8. Not sure how to get the PHPStan to ignore the It's not clear to me what the |
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.
Hi! In general it looks good for me as a basic setup. I left one comment to improve performance.
No need to fix src/Metadata/Driver/DoctrineTypeDriver.php
in this PR - it requires separate PR. :)
src/Handler/UnionHandler.php
Outdated
* For determining types of primitives, it is necessary to reorder primitives so that they are tested from lowest specificity to highest: | ||
* i.e. null, true, false, int, float, bool, string | ||
*/ | ||
private function reorderTypes(array $type): array |
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.
Let's move it into TypedPropertiesDriver
. In that way it will be reorder once & cached, not for each deserialisation.
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.
Good idea.
Seems like the remaining CI issues are in the |
@scyzoryck Yep, I think we've addressed all issues. I'm happy for you to merge when ready! |
@idbentley thanks for contribution! You are welcome with the next Pull Requests! :) Could you test it with your projects & dev version of the package, please? :) Best, Marcin |
it would be great to have this handler integrated in the bundle as well |
@goetas I'm currently working on a PR to expand this functionality to support Objects, arrays, non primitive data types. I thought it would make sense to get it into documentation and any build targets once that PR is ready as well. |
@idbentley I have talked a little with @scyzoryck about it, deserializing objects used in unions is certainly a good thing to have but I do not have any idea on how to make it work.... how to decide to which class to map an arbitrary data structure? do you have any idea on how to do so? |
@idbentley this crashes here with It calls MetadataFactory::getClassHierarchy() with 'union' input. calling final class Foo
{
public function __construct(
public A|B $union,
) { |
Yup, it should ignore unsupported cases. Good luck!
…On Fri, Jul 19, 2024, 17:35 Ian Bentley ***@***.***> wrote:
@simPod <https://github.com/simPod> that's definitely a bad way of
handling the issue, and I'm gonna look into more graceful failure. However,
I think your main problem is that there is currently only support for
unions of primitives at this time. See #1549
<#1549> to follow progress
on my attempt at unions of objects.
—
Reply to this email directly, view it on GitHub
<#1546 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQAJMTPSFZVE3TR5EV3STZNEW43AVCNFSM6AAAAABKJYMCYGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZZGQ3TIMBRGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This is just a minor improvement on #1504 - addressing @goetas feedback, improving type detection and tests.