-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Recursive denormalize with property info #17193
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
Recursive denormalize with property info #17193
Conversation
- Refactored PR 14844 "Denormalize with typehinting" - Now using PropertyInfo to extract type information - Updated tests - Updated composer.json
- Refactoring: - Extract method for property denormalization - Guard clauses - Avoid else/elseif - 2 indents per function - CS fix
- Fix logical fault for nullables
…nglas) This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #17281). Discussion ---------- [Serializer] Unset object_to_populate after using it | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a The `object_to_populate` key must be unset after using it to avoid problems when normalizing sub objects. Needed for #17193. Commits ------- ff18b68 [Serializer] Unset object_to_populate after using it
Status: needs work |
@mihai-stancu all changes required for this PR are now merged in master. You can now safely rebase and finish it. The code should be moved in the new |
@mihai-stancu can you finish this one? I can do it (I'll keep your commits to give you full credit) if you're busy. |
Hi Kevin, I'm a bit busy indeed, if you could do it this week that would be fine. On 09:24, Tue, Feb 2, 2016 Kévin Dunglas notifications@github.com wrote:
|
This work is included in #17660 . |
…ursive denormalization and hardening) (mihai-stancu, dunglas) This PR was merged into the 3.1-dev branch. Discussion ---------- [Serializer] Integrate the PropertyInfo Component (recursive denormalization and hardening) | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16143, #17193, #14844 | License | MIT | Doc PR | todo Integrates the PropertyInfo Component in order to: * denormalize a graph of objects recursively (see tests) * harden the hydratation logic The hardening part is interesting. Considering the following example: ```php class Foo { public function setDate(\DateTimeInterface $date) { } } // initialize $normalizer $normalizer->denormalize(['date' => 1234], Foo::class); ``` Previously, a PHP error was thrown because the type passed to the setter (an int) doesn't match the one checked with the typehint. With the PropertyInfo integration, an `UnexpectedValueExcption` is throw instead. It's especially interesting for web APIs dealing with JSON documents. For instance in API Platform, previously a 500 error was thrown, but thanks to this fix a 400 HTTP code with a descriptive error message will be returned. (/cc @csarrazi @mRoca @blazarecki, it's an alternative to https://github.com/dunglas/php-to-json-schema for protecting an API). /cc @mihai-stancu Commits ------- 5194482 [Serializer] Integrate the PropertyInfo Component 6b464b0 Recursive denormalize using PropertyInfo
[2.7][Serializer] Feature using
PropertyInfo
to recursively denormalize values before calling the setter.Refactored #14844 "Denormalize with typehinting":
This PR replaces #16143.