zendframework / zend-inputfilter

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

MVC InputFilterPluginManager missing InputFilterAbstractFactory config #177

Closed vaclavvanik closed 5 years ago

vaclavvanik commented 5 years ago

InputFilterPluginManager in MVC environment does not create input filter defined in config.

Code to reproduce the issue

$config = [
    'input_filter_specs' => [
        MyInput::class => [
            //...
        ],
    ],
];

$inputFilter = $container->get(InputFilter\InputFilterPluginManager::class)->get(MyInput::class);

Expected results

InputFilterPluginManager creates defined InputFilter

Actual results

Exception thrown

Plugin of type MyInput is invalid; must implement Zend\InputFilter\InputFilterInterface or Zend\InputFilter\InputInterface

Imho this happens because Module.php provide incomplete config.

    public function getConfig()
    {
        $provider = new ConfigProvider();

        return [
            'service_manager' => $provider->getDependencyConfig(),
            'input_filters' => $provider->getInputFilterConfig(), // this line is missing
        ];
    }
vaclavvanik commented 5 years ago

@weierophinney do you think it is a bug? Should I create PR?

froschdesign commented 5 years ago

@vaclavvanik Please look at:

https://github.com/zendframework/zend-inputfilter/blob/a23e67d41de09bbc325543acb756ba448f182c20/src/Module.php#L30-L42

...and you will find input_filters.

froschdesign commented 5 years ago

Or do you try to add the entire specification as array in the configuration and not the factories?

Xerkus commented 5 years ago

Doesn't it say the problem right here:

Plugin of type MyInput is invalid; must implement Zend\InputFilter\InputFilterInterface or Zend\InputFilter\InputInterface

https://github.com/zendframework/zend-inputfilter/blob/a23e67d41de09bbc325543acb756ba448f182c20/src/InputFilterPluginManager.php#L125-L143

your MyInput class does not implement those interfaces or extend other class that does

froschdesign commented 5 years ago

@Xerkus I think @vaclavvanik wants to insert the input-filter specification as an array into the configuration and for this the InputFilterAbstractFactory must be added manually as described in the documentation:

Setup

When using zend-mvc version 2 releases, this functionality is disabled by default. To enable it, you must add the Zend\InputFilter\InputFilterAbstractServiceFactory abstract factory to the Zend\InputFilter\InputFilterPluginManager configuration, which is under the input_filters configuration key.

https://docs.zendframework.com/zend-inputfilter/specs/#setup

Xerkus commented 5 years ago

@froschdesign I see, $autoAddInvokableClass = true masked the problem.

vaclavvanik commented 5 years ago

@froschdesign as I wrote above I think, that it is a bug, that in Module.php is missing config line with input_filters. Which causes that InputFilterAbstractFactory is not registered in InputFilterPluginManager.

In ConfigProvider is InputFilterAbstractFactory registered.

froschdesign commented 5 years ago

@vaclavvanik Did you see the hint in the documentation?

vaclavvanik commented 5 years ago

In the docs is:

For Expressive when using the configuration manager, and for zend-mvc v3 releases, the functionality is enabled by default, assuming you are using the component installer.

I am using mvc v3 and InputFilterAbstractFactory is not registered... :-/

Xerkus commented 5 years ago

Just checked, docs are indeed wrong. It is not registered for any mvc version by default. Are there any reasons why we wouldn't want to enable it by default for mvc as well?

froschdesign commented 5 years ago

@vaclavvanik I'm confused, unfortunately. If you use version v3 then you should have also the last version of zend-inputfilter! And the latest of version of zend-inputfilter contains the InputFilterAbstractFactory!

Or I'm wrong?

froschdesign commented 5 years ago

See:

froschdesign commented 5 years ago

@vaclavvanik I will create a pull request when I'm back on my computer and will ping you for testing.

vaclavvanik commented 5 years ago

@froschdesign #162 fixed InputFilterAbstractFactory registration in ConfigProvider (Expressive). MVC v3 uses Module and in this class has not 'input_filters' config key in getConfig() which causes that InputFilterAbstractFactory is not registered... (really confusing)

froschdesign commented 5 years ago

@vaclavvanik

really confusing

Right, because in zend-form is the behaviour different. :confused: