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

[Config] Allow validating values using callables in ExprBuilder#19578

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

Closed

Conversation

@chalasr
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?yes
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/a

This PR is a proposal for adding the ability to pass any callable for validating values using the ExprBuilder, which accepts only closures ATM.

The problem with closures is they often involve to write redundant code such as useless assignments or intermediate methods or lots of arguments in theuse() part of the closure, as soon as the validation logic is decoupled from the configuration for instance.

Before

publicfunctiongetConfigTreeBuilder(){// ...$validator =$this->validator;$rootNode        ->children()            ->scalarNode('foo')                ->validate()                ->ifString()                    ->then(function ($v)use ($validator) {return$validator->validate($v); })                ->end()            ->end()        ->end()    ->end()}

After

// ...$rootNode        ->children()            ->scalarNode('foo')                ->validate()                ->ifString()                    ->then([$this->validator,'validate'])                ->end()            ->end()        ->end()    ->end()

It is a BC break but IMHO it worths it, ATM I don't see any use case where this would have a negative impact, except when overriding the changed methods (never saw such case).

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedAug 9, 2016
edited
Loading

As you spotted, it's a BC break, forbidden by our written policy.
Btw, on PHP 7.1, you could write:
->then(\Closure::fromCallable([$this->validator, 'validate'])) :)
and on PHP 5.4 you can already write:
->then(function ($v) {return $this->validator->validate($v);})

👎

@chalasrchalasr closed thisAug 9, 2016
@chalasrchalasr deleted the expr_builder_callable branchAugust 9, 2016 13:50
@ro0NL
Copy link
Contributor

Somewhere it is a shame this cant target 4.x :( the change itself is good imho.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@chalasr@nicolas-grekas@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp