Skip to content

[Serializer] Allow to access to the format and context in circular ref handler #27020

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

Merged

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Apr 23, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR symfony/symfony-docs#10318

Similar to #27017 but for circular reference handlers.

ping @meyerbaptiste

* @param object $object
* @param object $object
* @param string|null $format
* @param array $context
Copy link
Member

Choose a reason for hiding this comment

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

all these can be removed imho

Copy link
Member Author

Choose a reason for hiding this comment

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

It allows the IDE to discover those parameters. They could be dropped only when/if we'll uncomment the new parameters.

Copy link
Member

Choose a reason for hiding this comment

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

ok, then next question for me is: how will we make these real args in 5.0?
shouldn't we throw a deprecation somehow?

Copy link
Member

Choose a reason for hiding this comment

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

do we want them to be optional in 5.x ? I would say no (otherwise you would not be able to rely on them in the handler).

so I would trigger a deprecation in case they are not provided when calling the method.

and I suggest making this method @final, as the proper way to extend the handling of circular references is to register a handler, not to extend the method in child classes.

Copy link
Member

Choose a reason for hiding this comment

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

making this method @Final

if that fits, then that's the best, as just adding the annotation will trigger a deprecation notice automatically

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 for final

{
$format = @func_get_arg(1) ?: null;
$context = @func_get_arg(2) ?: array();
Copy link
Member

Choose a reason for hiding this comment

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

please use func_num_args instead of @

Copy link
Member Author

Choose a reason for hiding this comment

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

done

*
* @return mixed
*
* @throws CircularReferenceException
*/
protected function handleCircularReference($object)
protected function handleCircularReference($object/*, ?string $format = null, array $context = array()*/)
Copy link
Member

Choose a reason for hiding this comment

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

the ? should be removed
don't miss adding @final also as discussed above

Copy link
Member Author

Choose a reason for hiding this comment

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

I change it, but for reference:

Typed properties cannot have a null default value, unless the type is explicitly nullable (?Type). This is in contrast to parameter types, where a null default value automatically implies a nullable type. We consider this to be a legacy behavior, which we do not wish to support for newly introduced syntax.

https://wiki.php.net/rfc/typed_properties_v2

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, but same as array() vs []: we prefer consistency across branches, and not all of them support this, so it's too early to consider.

@dunglas dunglas force-pushed the serializer-circular-ref-extra branch from fa5b6fd to b58cae4 Compare June 30, 2018 09:29
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM, just one minor comment.

@@ -190,16 +190,23 @@ protected function isCircularReference($object, &$context)
* If a circular reference handler is set, it will be called. Otherwise, a
* {@class CircularReferenceException} will be thrown.
*
* @param object $object
* @final
Copy link
Member

Choose a reason for hiding this comment

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

@Final since Symfony 4.2

@dunglas dunglas force-pushed the serializer-circular-ref-extra branch from fc704cf to 99f829e Compare July 3, 2018 20:18
@nicolas-grekas
Copy link
Member

Thank you @dunglas.

@nicolas-grekas nicolas-grekas merged commit 99f829e into symfony:master Jul 7, 2018
nicolas-grekas added a commit that referenced this pull request Jul 7, 2018
… in circular ref handler (dunglas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Serializer] Allow to access to the format and context in circular ref handler

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | todo

Similar to #27017 but for circular reference handlers.

ping @meyerbaptiste

Commits
-------

99f829e [Serializer] Allow to access to the format and context in circular ref handler
fabpot added a commit that referenced this pull request Sep 4, 2018
…rters (dunglas)

This PR was squashed before being merged into the 4.2-dev branch (closes #27021).

Discussion
----------

[Serializer] Allow to access extra infos in name converters

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes<!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | todo

Similar to #27017 and #27020 but for name converters.

ping @meyerbaptiste

Commits
-------

57fe017 [Serializer] Allow to access extra infos in name converters
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Sep 11, 2018
…other infos in callbacks and max depth handler (dunglas, javiereguiluz)

This PR was merged into the master branch.

Discussion
----------

[Serializer] Allow to access to the context and various other infos in callbacks and max depth handler

symfony/symfony#27020
symfony/symfony#27017

Commits
-------

672b374 Minor reword
7c3e620 Fix, and document setCircularReferenceHandler's new parameters
a4dad43 [Serializer] Allow to access to the context and various other infos in callbacks and max depth handler
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
nicolas-grekas added a commit that referenced this pull request Jun 8, 2019
…anagi)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Serializer] Remove last deprecated/obsolete paths

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #28316, #28709, #31030, #27020, #29896, 16f8a13#r201060750   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A <!-- required for new features -->

This should fix the last deprecations & obsolete code paths for the Serializer component.

Commits
-------

c703b35 [Serializer] Remove last deprecated/obsolete paths
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