8000 [Serializer] Fine-tune `ContextBuilder::withContext()` by chalasr · Pull Request #46179 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Fine-tune ContextBuilder::withContext() #46179

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
merged 1 commit into from
Apr 26, 2022

Conversation

chalasr
Copy link
Member
@chalasr chalasr commented Apr 26, 2022
Q A
Branch? 6.1
Bug fix? no
New feature? yes, small DX improvement
Deprecations? no
Tickets -
License MIT
Doc PR symfony/symfony-docs#16753

Allows to skip calling toArray() on the context builder when it is passed to withContext():

$contextBuilder = (new CsvEncoderContextBuilder())
  ->withContext($contextBuilder)
  ->withDelimiter('-')

instead of

$contextBuilder = (new CsvEncoderContextBuilder())
  ->withContext($contextBuilder->toArray())
  ->withDelimiter('-')

Allowing to do the same when passing the context to serialize() would require to revisit the SerializerInterface, which we can consider for 6.2.
/cc @mtarld

Copy link
Contributor
@mtarld mtarld left a comment

Choose a reason for hiding this comment

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

Nice addition!
Just one little nitpick

@nicolas-grekas
Copy link
Member

Thank you @chalasr.

@nicolas-grekas nicolas-grekas merged commit 7a21a57 into symfony:6.1 Apr 26, 2022
@chalasr chalasr deleted the with-context branch April 26, 2022 17:13
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 27, 2022
…en possible (chalasr)

This PR was merged into the 6.1 branch.

Discussion
----------

[Serializer] Skip calling `ContextBuilder::toArray()` when possible

<!--

If your pull request fixes a BUG, use the oldest maintained branch that contains
the bug (see https://symfony.com/releases for the list of maintained branches).

If your pull request documents a NEW FEATURE, use the same Symfony branch where
the feature was introduced (and `6.x` for features of unreleased versions).

-->

Leverages symfony/symfony#46179

Commits
-------

be1bd78 [Serializer] Skip calling `ContextBuilder::toArray()` when possible
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.

5 participants
0