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] Add context builders#43973

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

@mtarld
Copy link
Contributor

@mtarldmtarld commentedNov 9, 2021
edited
Loading

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
TicketsFixes partially#30818
LicenseMIT
Doc PRTODO

This PR introduces ContextBuilders as discussed in#30818.

The main idea here is to introduce an abstract context builder that could be extended to create concrete context builders.
These context builders will allow serialization context construction using withers (maybe setters are better?) while providing validation, documentation, and IDE autocompletion.
Once construction is ready,toArray (maybebuild is better?) can be called to generate the actual serialization context.

For example:

useSymfony\Component\Serializer\Context\Encoder\CsvEncoderContextBuilder;useSymfony\Component\Serializer\Context\Normalizer\DateTimeNormalizerContextBuilder;$initialContext = ['custom_key' =>'custom_value']);$contextBuilder = (newDateTimeNormalizerContextBuilder()  ->withContext($initialContext)  ->withFormat('Y_m_d')  ->withTimezone('GMT');$contextBuilder = (newCsvEncoderContextBuilder())  ->withContext($contextBuilder->toArray())  ->withDelimiter('-')  ->withHeaders(['foo','bar']);$this->serializer->serialize($data,'csv',$contextBuilder->toArray());// Serialization context will be:// [//   'custom_key' => 'custom_value',//   'datetime_format' => 'Y_m_d',//   'datetime_timezone' => DateTimeZone instance,//   'csv_delimiter' => '-',//   'csv_headers' => ['foo', 'bar'],// ]

ismail1432, welcoMattic, and chalasr reacted with thumbs up emojidunglas, welcoMattic, and dbrumann reacted with heart emojiwelcoMattic reacted with rocket emoji
@carsonbotcarsonbot added this to the6.0 milestoneNov 9, 2021
@mtarldmtarldforce-pushed thefeature/serializer-context-builder branch from1a6e2e3 to0478eb0CompareNovember 9, 2021 13:11
@mtarldmtarld changed the titleAdd context builers[Serializer] Add context builersNov 9, 2021
@mtarldmtarld changed the title[Serializer] Add context builers[Serializer] Add context buildersNov 9, 2021
@carsonbotcarsonbot changed the title[Serializer] Add context buildersAdd context buildersNov 9, 2021
@ogizanagiogizanagi modified the milestones:6.0,6.1Nov 9, 2021
@mtarldmtarldforce-pushed thefeature/serializer-context-builder branch from0478eb0 toc86c320CompareNovember 10, 2021 14:20
@mtarldmtarld requested a review fromdunglasNovember 10, 2021 14:22
@mtarldmtarldforce-pushed thefeature/serializer-context-builder branch 2 times, most recently from44e5b18 to86b2834CompareNovember 12, 2021 14:51
@mtarldmtarld changed the base branch from6.0 to6.1December 24, 2021 10:08
@mtarldmtarld changed the titleAdd context builders[Serializer] Add context buildersDec 24, 2021
@mtarldmtarldforce-pushed thefeature/serializer-context-builder branch from86b2834 toabacfdfCompareDecember 24, 2021 10:09
@mtarldmtarld requested a review fromdunglasDecember 24, 2021 10:30
@carsonbotcarsonbot changed the title[Serializer] Add context buildersAdd context buildersDec 25, 2021
Copy link
Member

@dunglasdunglas left a comment

Choose a reason for hiding this comment

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

Very good DX improvement! This also needs a rebase.

@mtarldmtarldforce-pushed thefeature/serializer-context-builder branch 2 times, most recently fromc2739a4 tobe6b0aaCompareJanuary 10, 2022 11:26
Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

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

@mtarld Can you rebase?

@mtarldmtarldforce-pushed thefeature/serializer-context-builder branch from48f7b82 tof1b078cCompareJanuary 26, 2022 08:12
@chalasr
Copy link
Member

Thank you@mtarld.

mtarld reacted with hooray emoji

@chalasrchalasr merged commitfac3060 intosymfony:6.1Feb 2, 2022
@mtarldmtarld deleted the feature/serializer-context-builder branchFebruary 2, 2022 18:13
@fabpotfabpot mentioned this pull requestApr 15, 2022
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull requestApr 26, 2022
…mtarld)This PR was merged into the 6.1 branch.Discussion----------[Serializer] Add context builders documentationRelated tosymfony/symfony#43973Closessymfony#16470Commits-------7be3c93 [Serializer] Add context builders documentation
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dunglasdunglasdunglas approved these changes

@welcoMatticwelcoMatticwelcoMattic approved these changes

@chalasrchalasrchalasr approved these changes

+1 more reviewer

@ismail1432ismail1432ismail1432 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

8 participants

@mtarld@chalasr@dunglas@welcoMattic@ismail1432@nicolas-grekas@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp