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

[OptionsResolver] Add prototype definition support for nested options#39913

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
fabpot merged 1 commit intosymfony:5.xfromyceruto:options_resolver_prototype
May 1, 2021

Conversation

@yceruto
Copy link
Member

@ycerutoyceruto commentedJan 21, 2021
edited
Loading

QA
Branch?5.x
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#34207
LicenseMIT
Doc PRsymfony/symfony-docs#...

This proposal adds a new methodsetPrototype(true) to theOptionsResolver component to mark options definition as array prototype:

$this->resolver    ->setDefault('connections',staticfunction (OptionsResolver$resolver) {// nested option$resolver            ->setPrototype(true)// <- the new method            ->setRequired('table')            ->setDefaults(['user' =>'root','password' =>null]);    });

This feature will allow passing options this way:

$this->resolver->resolve(['connections' => ['default' => [// <- the array index "default" is optional and validation free'table' =>'default',        ],'custom' => ['user' =>'foo','password' =>'pa$$','table' =>'symfony',        ],    ],])

You can add as many items as you want with the advantage of validating each item according to its prototype definition.

The result for this example would be:

['connections' => ['default' => ['user' =>'root','password' =>null,'table' =>'default',        ],'custom' => ['user' =>'foo','password' =>'pa$$','table' =>'symfony',        ],    ],]

This feature is feasible only for nested options so far and the nested option (e.g. "connections") must be of type array of array.

See the test cases for more details about this feature.

Cheers!

@carsonbot
Copy link

Hey!

I didn't know that was capable of this emotion. I really really like reviewing this PR. Well done.

I think@lmillucci has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@ycerutoycerutoforce-pushed theoptions_resolver_prototype branch from9daae60 toda5ebafCompareJanuary 28, 2021 20:13
@yceruto
Copy link
MemberAuthor

There is only one thing left to clarify here, because I'm guessing that prototyping shouldn't be supported as root definition (only for nested options) do we want to throw an exception in case someone tries to do it? I mean, having a prototyped root definition.

@ycerutoycerutoforce-pushed theoptions_resolver_prototype branch fromda5ebaf to8b078f4CompareJanuary 31, 2021 22:07
@azatyan
Copy link
Contributor

Hi@yceruto hope, you're doing well bro.
In my opinion, yes, adding an exception will help developers to understand faster this feature.

yceruto reacted with thumbs up emoji

@ycerutoycerutoforce-pushed theoptions_resolver_prototype branch 3 times, most recently from846f42c to6672a13CompareFebruary 20, 2021 15:30
Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

Can you rebase on current 5.x?

@ycerutoycerutoforce-pushed theoptions_resolver_prototype branch from6c83da9 to29d41b1CompareApril 18, 2021 13:38
@yceruto
Copy link
MemberAuthor

Done.

azatyan reacted with hooray emoji

@fabpot
Copy link
Member

Thank you@yceruto.

@fabpotfabpot merged commit0489ffc intosymfony:5.xMay 1, 2021
@fabpotfabpot mentioned this pull requestMay 1, 2021
@ycerutoyceruto deleted the options_resolver_prototype branchMay 2, 2021 01:49
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull requestMay 10, 2021
…method (yceruto)This PR was merged into the 5.3-dev branch.Discussion----------[OptionsResolver] Documenting new setPrototype() methodPR:symfony/symfony#39913Fix:symfony#15301Commits-------04316b2 Documenting prototype options
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

5.3

Development

Successfully merging this pull request may close these issues.

OptionsResolver: validate nested array item structure

6 participants

@yceruto@carsonbot@azatyan@fabpot@nicolas-grekas@Nyholm

[8]ページ先頭

©2009-2025 Movatter.jp