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
I've removed the Collections so that
InputInterface
is completely decoupled from bothZend\Filter
andZend\Validator
. That's not to say that those components shouldn't be used. But, we should be free to filter and validate with any potential implementation. This greatly simplifies how a combined sanitation and validation component is built.How is an input filtered? Maybe it's a
FilterChain
, but maybe it isn't. Don't paint the dev into a corner and force them to use something they may not want to.Implicit design is bad. Always be explicit and don't leave the implementation open to assumptions, or rely on comments to document behavior.