zendframework / zend-inputfilter

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

Make symmetric the scenarios when required is true/false #55

Closed Maks3w closed 9 years ago

Maks3w commented 9 years ago

There is no reason for to have differences when required is true or false and the value is always set.

Maks3w commented 9 years ago

@weierophinney I've reopen this because restore the behavior of 2.3.

Maks3w commented 9 years ago

From 2.3.9 I can upgrade without BC Breaks except for this one and the validator renaming for PHP7 compliance (Int > IsInt)

Maks3w commented 9 years ago

Workaround (Recommended, rely on allow_empty:false/continue_if_empty:false is now deprecated):

Before:

array(
    'name' => 'password',
    'required' => false,
    'filters' => array(),
    'validators' => array(),
    'error_message' => 'This field cannot be empty',
    'allow_empty' => true,
    'continue_if_empty' => true,
)

After:

array(
    'name' => 'password',
    'required' => false,
    'filters' => array(),
    'validators' => array(
        0 => array(
            'break_chain_on_failure' => true,
            'name' => 'Zend\\Validator\\NotEmpty',
            'options' => array(),
        ),
    ),
    'error_message' => 'This field cannot be empty',
    'allow_empty' => false,
    'continue_if_empty' => false,
)
Maks3w commented 9 years ago

We can again discard this because the feature to fix is now deprecated and workaround exists