zendframework / zend-inputfilter

InputFilter component from Zend Framework
BSD 3-Clause "New" or "Revised" License
64 stars 50 forks source link

InputFilter::getValues() does not throw like it should #143

Closed Erikvv closed 7 years ago

Erikvv commented 7 years ago

If the validation failed, according to the docblock, it should throw an exception if you try to get the filtered values anyways.

However this does not happen.

What Exception type should it throw? Should we define a new type "ValidationFailedException" or sth?

This is still a relevant question for when we get stateless InputFilters

svycka commented 7 years ago

OMG this would cause BC break for me please don't do it now even if this is desired behavior.

Ocramius commented 7 years ago

Closing as per @svycka's review.

The API of the validators should generally be changed as such (or similar) when having a chance:

interface Validator
{
    public function validate($inputValue) : ValidationResult;
}

class ValidationResult
{
    public function isValid() : bool { ... }
    public function inputValue() { ... }
    public function validValue() { ... }
    public function errorMessages() : array { ... }
}

Just pseudo-code, but you get the gist.