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();
}
@bakura10
You are correct,
filter
returns filtered data, andvalidate
andfilterAndValidate
return aValidationResultInterface
.I want the developer to be free to choose how data is filtered and how data is validated, including using external libraries. If
Zend\Filter\FilterChain
orZend\Validator\ValidatorChain
are defined in the interface, it limits the implementation to only those classes.I can't use this component without also using
Zend\Filter
andZend\Validator
. In order to make it easier to adopt ZF, every component should be decoupled to eliminate dependencies. ZF components should still be suggested, or recommended, obviously.