Skip to content

[RFC] Drop auto injection of NotEmpty validator for required inputs #168

@gsteel

Description

@gsteel

Problem

Auto injecting a NotEmpty validator is very possibly not wanted in some situations but completely unavoidable if you mark an input as required.

If you are translating your error messages, the auto-injected validator will not receive a translator instance and will yield the default (probably english) error message.

Iterating over and manipulating the validator inside Input relies on concrete methods in ValidatorChain that are not present in ValidatorChainInterface.
Furthemore, the chain that is provided or configured should not, IMO, be mutated after it has been attached.

Proposed Solution

Whether a field is "empty" or not, and whether that matters is a validation concern and should be entirely delegated to the validator chain.

It should be the users responsibility to add sufficient validation to each input for their use case, therefore, I'd suggest:

  • Complete removal of Input::injectNotEmptyValidator(), Input::prepareRequiredValidationFailureMessage() and related methods
  • Removal of Input::setRequired() and Input::isRequired() - again, this is a validation concern and part of the chain configuration

Impact to users

… is quite significant…

Any fields/inputs that do not configure validation beyond marking the input as required would pass validation for empty values where previously they would not have.

This could possibly be mitigated by throwing an exception when setRequired() is called, or, the required key is present in a specification, alerting users to the change.

This would force users to audit input filters and specs for sufficient validation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions