Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] ObjectNormalizer#13257

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@dunglas
Copy link
Member

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
LicenseMIT
Doc PRnot yet

PropertyAccessNormalizer is a new normalizer leveraging the PropertyAccess Component. It is able to handle classes containing both public properties and properties only accessibles trough getters / setters / issers / hassers...

As it extendsAbstractNormalizer, it supports circular reference handling, name converters and existing object population.
What do you think about making this new normalizer the default one as it's the most convenient to use and the most consistent with the behavior of other components.
#13120,#13252 and#13255 need to be merged to make this PR working.

@dunglas
Copy link
MemberAuthor

If you want to play with this new normalizer (or hack it), I've created a branch including all Serializer PR waiting to be merged (including this one):https://github.com/dunglas/symfony/tree/new_serializer

To use it in a standard edition install, add the following lines to yourcomposer.json:

"repositories": [        {"type":"vcs","url":"https://github.com/dunglas/symfony"        }    ],

Then replace with Symfony line to use this experimental branch:

"symfony/symfony":"dev-new_serializer as 2.7.0",

@mickaelandrieu
Copy link
Contributor

hi@dunglas, can you provide a practical sample of what this feature can do ?

@dunglas
Copy link
MemberAuthor

class MyObj{public$foo ='foo';public getBar()    {return 'bar';    }publicisBaz()    {returntrue;    }}$normalizer =new \Symfony\Component\Serializer\Normalizer\PropertyAccessNormalizer();var_dump($normalizer->normalize(newMyObj()));// Should output something like ['foo' => 'foo', 'bar' => 'bar', 'baz' => true]

@dunglas
Copy link
MemberAuthor

This normalizer also supports denormalization (for gettters / settersand properties), serialization groups (http://symfony.com/blog/new-in-symfony-2-7-serialization-groups), name converters (symfony/symfony-docs#4692), circular references handlers (symfony/symfony-docs#4299) and existing object population (#13252).

@fabpot
Copy link
Member

👍

The only "issue" I see is the name; I understand that you named your class after the property access component but I find it confusing as at first, I thought it was about "just" supporting class properties. If it becomes the default one (which I think is a good idea), we should find a better name.

@dunglas
Copy link
MemberAuthor

I agree, the name is confusing. What aboutObjectNormalizer?

@fabpot
Copy link
Member

@dunglas If this is the "definitive" serializer, that sounds much better to me.

@mickaelandrieu
Copy link
Contributor

totaly agree with@fabpot , this should become the default serializer!

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be moved torequire if it becomes the default normalizer?

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the default serializer in the full stack framework, but please don't add more "hard" dependencies between (standalone) components !

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@mickaelandrieu good point

@dunglas
Copy link
MemberAuthor

What do you think about moving the code listing accessible "properties" (trough public properties and methods) -https://github.com/dunglas/symfony/blob/seriaizer_property_access_normalizer/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php#L62-L89 - in the PropertyAccess Component?

It can be useful in other contexts (in fact, I've an use case in a private project right now). cc@fabpot@webmozart

Copy link
Member

Choose a reason for hiding this comment

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

you should rely on autoloading instead

@dunglasdunglasforce-pushed theseriaizer_property_access_normalizer branch 4 times, most recently fromb344af7 to2f69022CompareFebruary 3, 2015 07:10
@dunglasdunglas changed the title[Serializer] PropertyAccessNormalizer[Serializer] ObjectNormalizerFeb 3, 2015
@dunglasdunglasforce-pushed theseriaizer_property_access_normalizer branch 4 times, most recently from7531332 toe1cf645CompareFebruary 4, 2015 12:59
@dunglas
Copy link
MemberAuthor

Rebased. Should be ready for the merge now.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 thanks a lot!

@dunglas
Copy link
MemberAuthor

I've fixed tests withcomponents=low. Is there any more work to be done before getting this PR merged?

Copy link
Member

Choose a reason for hiding this comment

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

Is it on purpose you don't use anelse block on the next statement? It can avoid a call to thethis->propertyAccessor->getValue

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@jeremy-derusse I don't understand what you mean.

Copy link
Member

Choose a reason for hiding this comment

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

You can replace

$attributeValue = $this->propertyAccessor->getValue($object, $attribute);if (array_key_exists($attribute, $this->callbacks)) {    $attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue);}

by

if (array_key_exists($attribute, $this->callbacks)) {    $attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue);} else {    $attributeValue = $this->propertyAccessor->getValue($object, $attribute);}

and avoid to call$this->propertyAccessor->getValue($object, $attribute); whenarray_key_exists($attribute, $this->callbacks) is false.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

No because$attributeValue in$attributeValue = call_user_func($this->callbacks[$attribute], $attributeValue); will be undefined.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Or worse, the value of the previous loop iteration.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Ok I got it. But still no because the attribute value will never be retrieved. We need it even if a callback is not registered.

@dunglasdunglasforce-pushed theseriaizer_property_access_normalizer branch froma562e42 toa4b6421CompareMarch 1, 2015 17:04
@dunglasdunglasforce-pushed theseriaizer_property_access_normalizer branch 3 times, most recently fromfca94f2 to6a12f1eCompareMarch 3, 2015 14:59
@dunglas
Copy link
MemberAuthor

Rebased.

@dunglas
Copy link
MemberAuthor

ping @symfony/deciders

@dunglasdunglasforce-pushed theseriaizer_property_access_normalizer branch from6a12f1e to0050bbbCompareMarch 6, 2015 10:53
@dunglasdunglas merged commit0050bbb intosymfony:2.7Mar 6, 2015
dunglas added a commit that referenced this pull requestMar 6, 2015
This PR was merged into the 2.7 branch.Discussion----------[Serializer] ObjectNormalizer| Q             | A| ------------- | ---| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| License       | MIT| Doc PR       | not yet`PropertyAccessNormalizer` is a new normalizer leveraging the PropertyAccess Component. It is able to handle classes containing both public properties and properties only accessibles trough getters / setters / issers / hassers...As it extends `AbstractNormalizer`, it supports circular reference handling, name converters and existing object population.What do you think about making this new normalizer the default one as it's the most convenient to use and the most consistent with the behavior of other components.#13120,#13252 and#13255 need to be merged to make this PR working.Commits-------0050bbb [Serializer] Introduce ObjectNormalizer
@mickaelandrieu
Copy link
Contributor

👍 thanks for this improvement@dunglas !

dunglas added a commit that referenced this pull requestApr 27, 2015
…nnotations (dunglas)This PR was merged into the 2.7 branch.Discussion----------[Serializer] Supports hassers and setters for groups annotations| Q             | A| ------------- | ---| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | n/aFor more coherence with the new `ObjectNormalizer` (#13257), this PR allows to add `@Groups` annotations on hasser and setter methods too.Commits-------9c87ecc [Serializer] Supports hassers and setters for groups annotations
@dunglasdunglas deleted the seriaizer_property_access_normalizer branchDecember 5, 2015 09:02
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@dunglas@mickaelandrieu@fabpot@stof@jderusse@Tobion@xabbuh

[8]ページ先頭

©2009-2025 Movatter.jp