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

Fix issue when transforming DTOs with nested DTOs into array or json #53

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

WendellAdriel
Copy link
Owner

This PR fixes the issue reported on #50

@WendellAdriel WendellAdriel merged commit 9d05280 into main Oct 6, 2023
8 checks passed
@WendellAdriel WendellAdriel deleted the fix-dto-transform branch October 6, 2023 11:22
@Briareos17
Copy link

Big thanks for fast response, but what about collection of DTOs? toArray simply return array ot DTO instances but each need to be array

@Briareos17
Copy link

Would be great to implement some kind of reverse casting, so all typehinted or casted properties will cast back on serialize

@WendellAdriel
Copy link
Owner Author

Oooh, completely forgot about the Collections 😅
I'll add a fix for that as well, now the reverse casting is not something I plan to add right now to the package

$value instanceof Collection => $value->toArray(),
$value instanceof Model => $value->toArray(),
$value instanceof SimpleDTO => $this->transformDTOToArray($value),
is_object($value) => (array) $value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has broken Enums. A UnitEnum is now ['name' => 'Foo'] and a BackedEnum is now ['name' => Foo, 'value' => 'Bar']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants