A few notes from my personal gripes about what InputFilter
is and does.
InputFilter
is a terrible name as the class mixes sanitation and validation. Rename to something far more appropriate (e.g.InputManager
?).- Data should only be processed, not stored - remove
setData()
For example, if both raw and sanitized data are required:
$sanitizedData = $this->inputManager->sanitize($data->toArray());
$validationResult = $this->inputManager->validate($sanitizedData);
if ($validationResult->isValid()) {
// hooray!
} else {
$messages = $validationResult->getMessages();
}
Also, if all we need is the result:
$validationResult = $this->inputManager->sanitizeAndValidate($data->toArray());
if ($validationResult->isValid()) {
// hooray!
} else {
$messages = $validationResult->getMessages();
}
Hmm. I may agree on the naming but InputFilter seems the best for me now (it's not because it does validation also that it should be named InputValidatorFilter or something like this).
Currently, the same result is achieved like this:
Furthemore:
If I understand this correctly, you will filter data even if the result is not valid. This is useless and will consume time and memory for nothing.
I find your abstraction a bit more complicated to use. People may think that isValid does filtering but it does not. I don't think we need to introduce explicit "validate" and "filter". Validation is implicit when doing isValid, and filtering is implicit when doing getValues.
I don't understand your FilterCollectionInterface and ValidatorCollectionInterface. To me this is really similar to ValidatorChain and FilterChain. This would mean that your ValidatorCollection would consume a ValidatorChain ? Pretty complex for few benefits imho.
Your input interface seems definitely wrong to me. An InputFilter consumes validator chain and filter chain, I don't really get the point of an Input filter interface extending a ValidatorCollection or FilterCollection.
To be honest Input filter is to my opinion one of the best ZF 2 component. It's simple to use, powerful and do it right with abstraction, without being to complicated to use. My rewrite is mostly clean the code to remove edge cases support and use much more efficient data structures.