A few notes from my personal gripes about what InputFilter is and does.
InputFilteris 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();
}
Yes yes, all of this is nice. I know. But please, show me with interfaces how you deal with validators here? And I want to keep the type hinting to ValidatorInterface somewhere (of course).