-
-
Notifications
You must be signed in to change notification settings - Fork 29
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Replace Input with a chain of callbacks. #6
Comments
In which context do you want to create and execute the chain. I think this could lead to heavy objects, because there are so much dependencies (Hydrator, Validator, Filter, ...). And in my opinion the code is really hard to read. But aside of this, it could be a great feature. Originally posted by @zf2timo at zendframework/zend-inputfilter#87 (comment) |
Chain can be created from static methods and added to input filters $inputFilter->addInput("input name", Chain $chain);
$result = $inputFilter->resolve($inputValuesArray);
$result->isValid();
$result->getValues(); About the code legibility this is as easy as use local vars or refactor dependent components for be API compatible. $removeWhitespaces = ...;
$validateIsFormattedAsADate = ...;
$chain
->then($removeWhitespaces)
->then($validateIsFormattedAsADate)
->then(null, $setFallbackValue)
; About the dependencies, there is no dependencies, just callables. Originally posted by @Maks3w at zendframework/zend-inputfilter#87 (comment) |
Note this way of make chains could replace or remove ValidatorChain and FilterChain classes Originally posted by @Maks3w at zendframework/zend-inputfilter#87 (comment) |
while I like the idea of replacing Originally posted by @stefanotorresi at zendframework/zend-inputfilter#87 (comment) |
Well, who said this things could not be async in the future or with alternative PHP engines. Originally posted by @Maks3w at zendframework/zend-inputfilter#87 (comment) |
If that was the actual intention, I'd rather have the input filter wrapped in a promise via a dedicated implementation like reactphp/promise, or introduce a new zend component for that purpose, but then again... why would you do that? Originally posted by @stefanotorresi at zendframework/zend-inputfilter#87 (comment) |
I started to think the best way of build a custom pipe of filters and validators where you can filter after validation, etc.
I propose replace
Zend\InputFilter\Input
with a custom chain of methods like A+ promises.For resume A+ promises have the following main properties along others I won't detail here:
then(callback success = null, callback error = null)
So basically the chain do two kind of things. Transformations of the input value and reject the chain if is invalid.
Options:
Reject promise using a reject method callback instead throwing exceptions.
->then($reject($errror) {}, $inputValue);
Benefits of this design:
Thoughts?
/cc @weierophinney, @Ocramius, @bakura10, @zendframework/community-review-team
Originally posted by @Maks3w at zendframework/zend-inputfilter#87
The text was updated successfully, but these errors were encountered: