Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

BC in validators context value #16

@svycka

Description

@svycka

Before 2.5.2 context values was all inputs added to inputfilter but 2.5.2 changed this and now returns raw values passed to inputFilter. I Think this should be and is correct behavior, but unfortunately now it is BC. This should be at least mentioned in release notes or fixed.

example:

<?php

require __DIR__ . '/vendor/autoload.php';

class MyFilter extends Zend\InputFilter\InputFilter
{
    public function init()
    {
        $this->add([
            'name' => 'field1',
            'required' => true,
        ]);

        $this->add([
            'name' => 'field2',
            'required' => true,
            'validators' => [
                [
                    'name' => 'Zend\Validator\Callback',
                    'options'  => [
                        'callback' => function ($value, $context) {
                            var_dump($context);
                            return true;
                        },
                    ],
                ],
            ],
        ]);
    }
}

$app = Zend\Mvc\Application::init([
    'modules' => [
    ],

    'module_listener_options' => [
        'module_paths' => [
        ],

        'config_glob_paths' => [
        ],
    ],

    'input_filters' => [
        'invokables' => [
            'MyFilter' => 'MyFilter',
        ],
    ],
]);

$manager = $app->getServiceManager()->get('InputFilterManager');
$filter = $manager->get('MyFilter');

echo "\n";
echo "#------------------------------\n";
echo "# Test case\n";
echo "#------------------------------\n";
echo "\n";
$filter->setData([
    'field2' => 'foo',
]);

$filter->isValid();

output with versions =<2.5.1

#------------------------------
# Test case
#------------------------------

array(2) {
  'field1' =>
  NULL
  'field2' =>
  string(3) "foo"
}

output with versions =>2.5.2

#------------------------------
# Test case
#------------------------------

array(1) {
  'field2' =>
  string(3) "foo"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions