Skip to content

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

Closed
wants to merge 13 commits into from
Closed

Recursive denormalize with property info #17193

wants to merge 13 commits into from

Conversation

mihai-stancu
Copy link
Contributor

[2.7][Serializer] Feature using PropertyInfo to recursively denormalize values before calling the setter.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR n/a

Refactored #14844 "Denormalize with typehinting":

  • Now using (optional) PropertyInfo to extract type information
  • Updated tests
  • Updated composer.json

This PR replaces #16143.

dunglas and others added 13 commits December 22, 2015 19:41
- 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
fabpot added a commit that referenced this pull request Jan 12, 2016
…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
@nicolas-grekas
Copy link
Member

Status: needs work

@dunglas
Copy link
Member

dunglas commented Jan 27, 2016

@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 AbstractObjectNormalizer class.

@dunglas
Copy link
Member

dunglas commented Feb 2, 2016

@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.

@mihai-stancu
Copy link
Contributor Author

Hi Kevin,

I'm a bit busy indeed, if you could do it this week that would be fine.
Otherwise I'll do it next week.

On 09:24, Tue, Feb 2, 2016 Kévin Dunglas notifications@github.com wrote:

@mihai-stancu https://github.com/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.


Reply to this email directly or view it on GitHub
#17193 (comment).

@mihai-stancu
Copy link
Contributor Author

This work is included in #17660 .

dunglas added a commit that referenced this pull request Apr 19, 2016
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants