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

[Validator] add Validation::createCallable()#31466

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:masterfromjanvernieuwe:callable-validator
Feb 4, 2020

Conversation

janvernieuwe
Copy link
Contributor

@janvernieuwejanvernieuwe commentedMay 10, 2019
edited by lyrixx
Loading

QA
Branch?4.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

This is an initial PR to check/discuss the implementation of a callable validator.
If there is interest in merging this, I will gladly update the docs and such.

The use case is mainly for validation of console questions, since the default validation has been removed in the latest version and i could not find an easy solution to replace it (if there already is some solution for this, i'm not aware of it) and the question helper uses callables.
This small class allows the standard symfony validators to be used in console questions, or any other location that requires a callable validator.

Example use case:

$io =newSymfonyStyle($input,$output);$required =newCallableValidator([newNotBlank()]);$wsdl =$io->ask('Wsdl location (URL or path to file)',null,$required);

As said before, this is by no means the final version, but I would like to know if there is interest in merging this (and receive some feedback about the implementation) before I put any more effort into this.

veewee and HeahDude reacted with heart emojiLanderstraeten reacted with rocket emoji
Copy link
Contributor

@SimperfitSimperfit left a comment

Choose a reason for hiding this comment

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

You should remove the two unrelated commits

@janvernieuwe
Copy link
ContributorAuthor

Updated it, guess my fork got out of sync

@ro0NL
Copy link
Contributor

instead of a new CallableValidator, which isn't really a validator from the component pov (as it's not a true ValidatorInterface implementation) ... what aboutValidation::createCallable($constraints): Closure

@lyrixxlyrixx changed the titleCallable validator[Console] Callable validatorJun 4, 2019
@lyrixxlyrixx changed the base branch from4.3 to4.4June 4, 2019 12:08
@janvernieuwe
Copy link
ContributorAuthor

janvernieuwe commentedJun 7, 2019
edited
Loading

@ro0NL that can work too, it should be pretty easy as something like this in the Validation class:

publicstaticfunctioncreateCallable(Constraint...$constraints):callable    {$validator =self::createValidator();returnstaticfunction ($value)use ($constraints,$validator) {$violations =$validator->validate($value,$constraints);if (0 !==$violations->count()) {thrownewLogicException((string)$violations);            }return$value;        };    }

Don't know if it is desirable to create a new Validator instance for each new callable though, but it shouldn't be too bad.

@janvernieuwejanvernieuweforce-pushed thecallable-validator branch 3 times, most recently from6fe4e80 to015b0c8CompareJuly 26, 2019 08:18
@janvernieuwe
Copy link
ContributorAuthor

Failures on travis don't seem to be related to any of my code changes as far as i can see...

@nicolas-grekasnicolas-grekas modified the milestones:next,4.4Oct 27, 2019
@nicolas-grekasnicolas-grekas changed the title[Console] Callable validator[Validator] add Validation::createCallable()Nov 5, 2019
return static function ($value) use ($constraints, $validator) {
$violations = $validator->validate($value, $constraints);
if (0 !== $violations->count()) {
throw new LogicException((string) $violations);

Choose a reason for hiding this comment

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

This should be a RuntimeException to me, or better: a class derived from RuntimeException modelled after ValidationFailedException from the Messenger component. WDYTN

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Added a new exception for this, let me know if you want to change the naming or anything.

@nicolas-grekasnicolas-grekas modified the milestones:4.4,nextNov 8, 2019
Copy link
Contributor

@ro0NLro0NL left a comment

Choose a reason for hiding this comment

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

nice feature 👍

@nicolas-grekas
Copy link
Member

can you please rebase+retarget for master?
if not no worries, we can do it on merger's side.

@janvernieuwe
Copy link
ContributorAuthor

I won't immediately have time for retargetting. So if it can be done on the merger's side, that'd be great!

@nicolas-grekasnicolas-grekas changed the base branch from4.4 tomasterJanuary 27, 2020 21:35
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

(I rebased the PR for master)

janvernieuwe reacted with heart emoji
@fabpot
Copy link
Member

Thank you@janvernieuwe.

fabpot added a commit that referenced this pull requestFeb 4, 2020
…euwe)This PR was merged into the 5.1-dev branch.Discussion----------[Validator] add Validation::createCallable()| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |This is an initial PR to check/discuss the implementation of a callable validator.If there is interest in merging this, I will gladly update the docs and such.The use case is mainly for validation of console questions, since the default validation has been removed in the latest version and i could not find an easy solution to replace it (if there already is some solution for this, i'm not aware of it) and the question helper uses callables.This small class allows the standard symfony validators to be used in console questions, or any other location that requires a callable validator.Example use case:```php$io = new SymfonyStyle($input, $output);$required = new CallableValidator([new NotBlank()]);$wsdl = $io->ask('Wsdl location (URL or path to file)', null, $required);```As said before, this is by no means the final version, but I would like to know if there is interest  in merging this (and receive some feedback about the implementation) before I put any more effort into this.Commits-------2e4f2ac [Validator] add Validation::createCallable()
@fabpotfabpot merged commit2e4f2ac intosymfony:masterFeb 4, 2020
@nicolas-grekasnicolas-grekas modified the milestones:next,5.1May 4, 2020
@fabpotfabpot mentioned this pull requestMay 5, 2020
@stof
Copy link
Member

I see an issue here: the callable creation always creates a new Validator object instead of allowing to use an existing one. This makes it incompatible with the DI integration, and so forbids using any constraint validator which has some dependency.
And it also makes it incompatible with any mapping configuration.

@nicolas-grekas
Copy link
Member

@stof good catch. What's your reco here? Revert? Improving? (in this case, could you work on a PR?)

@stof
Copy link
Member

Well, the variadic signature makes it hard to improve, as we cannot add an optional parameter to pass a validator instance.

@stof
Copy link
Member

My proposal: change the constraints from a variadic argument to an array argument (or maybeConstraintInterface[]|ConstraintInterface for the case of only one constraint), and add the validator as an optional second argument.

@stof
Copy link
Member

Btw, this is the main reason why I don't like variadic arguments: they lock the signature entirely.

nicolas-grekas added a commit that referenced this pull requestMay 19, 2020
…eCallable() (nicolas-grekas)This PR was merged into the 5.1 branch.Discussion----------[Validator] allow passing a validator to Validation::createCallable()| Q             | A| ------------- | ---| Branch?       | 5.1| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -As spotted by@stof in#31466 (comment)Commits-------1357cbf [Validator] allow passing a validator to Validation::createCallable()
symfony-splitter pushed a commit to symfony/validator that referenced this pull requestMay 19, 2020
…eCallable() (nicolas-grekas)This PR was merged into the 5.1 branch.Discussion----------[Validator] allow passing a validator to Validation::createCallable()| Q             | A| ------------- | ---| Branch?       | 5.1| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -As spotted by@stof insymfony/symfony#31466 (comment)Commits-------1357cbf8ed [Validator] allow passing a validator to Validation::createCallable()
@ogizanagiogizanagi mentioned this pull requestAug 17, 2020
fabpot added a commit that referenced this pull requestAug 17, 2020
This PR was merged into the 5.1 branch.Discussion----------Fix tests namespaces| Q             | A| ------------- | ---| Branch?       | 5.1 <!-- see below -->| Bug fix?      | no| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets       | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->| License       | MIT| Doc PR        | N/AFixes namespaces for tests introduced in#34869 &#31466, spotted by travis generating Composer warnings:```Deprecation Notice: Class Symfony\Component\Console\Tests\Output\NullOutputFormatterStyleTest located in ./src/Symfony/Component/Console/Tests/Formatter/NullOutputFormatterStyleTest.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///home/travis/.phpenv/versions/7.4.9/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201Deprecation Notice: Class Symfony\Component\Console\Tests\Output\NullOutputFormatterTest located in ./src/Symfony/Component/Console/Tests/Formatter/NullOutputFormatterTest.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///home/travis/.phpenv/versions/7.4.9/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201Deprecation Notice: Class Symfony\Component\Validator\Tests\Validator\ValidationTest located in ./src/Symfony/Component/Validator/Tests/ValidationTest.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///home/travis/.phpenv/versions/7.4.9/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201```Commits-------4e68c90 Fix tests namespaces
@janvernieuwejanvernieuwe deleted the callable-validator branchJanuary 15, 2021 00:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@SimperfitSimperfitSimperfit requested changes

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@ro0NLro0NLro0NL approved these changes

@dunglasdunglasAwaiting requested review from dunglas

@lyrixxlyrixxAwaiting requested review from lyrixx

@srozesrozeAwaiting requested review from sroze

Assignees
No one assigned
Projects
None yet
Milestone
5.1
Development

Successfully merging this pull request may close these issues.

8 participants
@janvernieuwe@ro0NL@nicolas-grekas@fabpot@stof@Simperfit@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp