8000 MVC InputFilterPluginManager missing InputFilterAbstractFactory config · Issue #177 · zendframework/zend-inputfilter · GitHub
[go: up one dir, main page]

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

MVC InputFilterPluginManager missing InputFilterAbstractFactory config #177

Closed
vaclavvanik opened this issue Jan 27, 2019 · 15 comments
Closed
Labels
Milestone

Comments

@vaclavvanik
Copy link

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
Copy link
Author

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

@froschdesign
Copy link
Member

@vaclavvanik
Please look at:

public function init($moduleManager)
{
$event = $moduleManager->getEvent();
$container = $event->getParam('ServiceManager');
$serviceListener = $container->get('ServiceListener');
$serviceListener->addServiceManager(
'InputFilterManager',
'input_filters',
'Zend\ModuleManager\Feature\InputFilterProviderInterface',
'getInputFilterConfig'
);
}

...and you will find input_filters.

@froschdesign
Copy link
Member

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

@Xerkus
Copy link
Member
Xerkus commented May 7, 2019

Doesn't it say the problem right here:

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

public function validate($plugin)
{
if ($plugin instanceof InputFilterInterface || $plugin instanceof InputInterface) {
// Hook to perform various initialization, when the inputFilter is not created through the factory
if ($plugin instanceof InitializableInterface) {
$plugin->init();
}
// we're okay
return;
}
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s or %s',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
InputFilterInterface::class,
InputInterface::class
));
}

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

@froschdesign
Copy link
Member

@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
Copy link
Member
Xerkus commented May 7, 2019

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

@vaclavvanik
Copy link
Author

@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
Copy link
Member

@vaclavvanik
Did you see the hint in the documentation?

@vaclavvanik
Copy link
Author

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
Copy link
Member
Xerkus commented May 9, 2019

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
Copy link
Member
froschdesign commented May 9, 2019

@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
Copy link
Member

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

@vaclavvanik
Copy link
Author

@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
Copy link
Member

@vaclavvanik

really confusing

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
0