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();
}
What are filter, validate and filterAndValidate suppose to return? To my understanding of your examples, filter returns an array of values, filterAndValidate and validate returns a ValidationResult ?
I'm not sure to understand this. How do you want to filter? A Filter chain does not force you anything. A Filter Chain is just a container for any filters. It can either be built-in filters, custom filters, callback…
I completely agree with you about implicit design, but it still has to be simple to use for the end-user. Introducing too much abstraction is bad for framework's adoption. I mean, can you show me a concrete use-case of something you'd like to do but cannot do with the current implementation ?