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();
}
I've already renamed the InputFilter to InputCollection (you can check it here: zendframework/zendframework#4772 (comment)).
Regarding Input stateless, my question is: how can you retrieve the raw value and filtered value if you never store it?
In my refactor, it uses RecursiveIteratorIterator: https://github.com/bakura10/zf2/blob/902416598924a1749096d2026e6e8c02e01c3c4e/library/Zend/InputFilter/InputCollection.php#L317-L336
What we get is only Input, not input collection, therefore the logic of required/not required is handled by the input, not input collection.
Regarding ValidationResult, I'll try to integrate it.