Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #28709 [Serializer] Refactor and uniformize the config by int…
…roducing a default context (dunglas) This PR was squashed before being merged into the 4.2-dev branch (closes #28709). Discussion ---------- [Serializer] Refactor and uniformize the config by introducing a default context | 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? | yes <!-- 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 <!-- required for new features --> This PR uniformizes how the Serializer's configuration is handled: * As currently, configuration options can be set using the context (options that weren't configurable using the context have been refactored to leverage it) * Normalizers and encoders' constructors now accept a "default context" * All existing global configuration flags (constructor parameters) have been deprecated in favor of this new default context * the stateless context is always tried first, then is the default context Some examples: ```php // Configuring groups globally // Before: not possible // After $normalizer = new ObjectNormalizer(/* deps */, ['groups' => 'the_default_group']); // Escaping Excel-like formulas in CSV files // Before $encoder = new CsvEncoder(',', '"', '\\', '.', true); // After $encoder = new CsvEncoder(['csv_escape_formulas' => true]); $encoder->normalize($data, 'csv', ['csv_escape_formulas' => false]); // Override for this call only ``` Benefits: * The DX is dramatically improved, configuration is always handled in similar way * The serializer can be used in fully stateless way * Every options can be configured globally * Classes that had constructors with a lot of parameters (like `CsvEncoder`) are now much easier to use * We'll be able to improve the documentation by adding a dictionary of all available context options for the whole component * Everything can be configured the same way TODO in subsequent PRs: * Add a new option in framework bundle to configure the context globally * Uniformize the constants name (sometimes the name if `FOO`, sometimes `FOO_KEY`) * Fix the "bug" regarding the format configuration in `DateTimeNormalizer::denormalize()` (see comments) * Maybe: move `$defaultContext` as the first parameter (before required services?) * Make `XmlEncoder` stateless Commits ------- 52b186a [Serializer] Refactor and uniformize the config by introducing a default context
- Loading branch information
Showing
20 changed files
with
854 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.