-
Notifications
You must be signed in to change notification settings - Fork 49
Ensure input_filters
config is honored in non-zend-mvc contexts
#137
Ensure input_filters
config is honored in non-zend-mvc contexts
#137
Conversation
Per https://discourse.zendframework.com/t/validatormanager-not-calling-custom-validator-factory/109/5?u=matthew the `input_filters` config key is not honored currently unless the application is within a zend-mvc context. This is due to the fact that `Zend\InputFilter\Module` wires configuration for the `Zend\ModuleManager\Listener\ServiceListener` in order to push merged service configuration into the plugin during bootstrap; no similar logic is available when not in a zend-mvc context, however. This patch fixes that situation by modifying the `InputFilterPluginManagerFactory` to do the following: - If a `ServiceListener` service exists, it returns the plugin manager immediately (old behavior). - Otherwise, it checks for the `config` service, and, if found, a `input_filters` key with an array value. When found, it feeds that value to a `Zend\ServiceManager\Config` instance and uses that to configure the plugin manager before returning it.
validators
config is honored in non-zend-mvc contextsinput_filters
config is honored in non-zend-mvc contexts
Failing tests are against |
@weierophinney does this mean that we no longer require to write our own factory for zend-expressive? also do you plan to add this to other plugin managers like validator, filter, view, controllers and others? |
Already done: zendframework/zend-filter/pull/56 |
oh nice didn't see this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
I would also add the factory for Here's how I implemented it in my library: use Interop\Container\ContainerInterface;
use Zend\Filter\FilterPluginManager;
use Zend\InputFilter\Factory;
use Zend\InputFilter\InputFilterPluginManager;
use Zend\Validator\ValidatorPluginManager;
class InputFilterFactoryFactory
{
public function __invoke(ContainerInterface $container)
{
$factory = new Factory($container->get(InputFilterPluginManager::class));
$factory->getDefaultFilterChain()->setPluginManager($container->get(FilterPluginManager::class));
$factory->getDefaultValidatorChain()->setPluginManager($container->get(ValidatorPluginManager::class));
return $factory;
}
} This is required to configure populate input filter using class ContactInputFilter extends InputFilter
{
public function __construct()
{
$this->add(
[
'name' => 'first_name',
'filters' => [
['name' => 'Foo'],
],
'validators' => [
['name' => 'Bar'],
],
]
);
$this->add(
[
'name' => 'content',
'filters' => [
['name' => 'StringTrim'],
],
]
);
}
} |
@mtymek are you sure this is required? I don't remember doing this. Maybe you not added filter and validators config providers to config? |
@froschdesign lines you mentioned will only work under $factory->getDefaultFilterChain()->setPluginManager($container->get('FilterManager')); My code uses |
@mtymek then I think this should be solved here https://github.com/zendframework/zend-filter/blob/master/src/ConfigProvider.php#L33 by adding FilterPluginManager::class and making 'FilterManager' as alias. This would solve this no? |
…or you have registered already these managers. |
@svycka indeed, this could work as well. Maybe it would be enough to add the aliases to @froschdesign I don't understand your remark. Can you elaborate? |
@mtymek — regarding this:
I'm not sure why you need that at all. zend-filter defines the I agree that we should likely add the FQCN as the service name pointing to the factory, and the shorter names as aliases to those, but after the proposed changes in this PR and the new tags I've created on the other components, it should all work seamlessly. |
Right :) The reason you see it is that is that I working on my lib before ConfigProvider was available in |
@mtymek No worries! Glad it's all sorted! |
Per https://discourse.zendframework.com/t/validatormanager-not-calling-custom-validator-factory/109/5?u=matthew the
input_filters
config key is not honored currently unless the application is within a zend-mvc context. This is due to the fact thatZend\InputFilter\Module
wires configuration for theZend\ModuleManager\Listener\ServiceListener
in order to push merged service configuration into the plugin during bootstrap; no similar logic is available when not in a zend-mvc context, however.This patch fixes that situation by modifying the
InputFilterPluginManagerFactory
to do the following:ServiceListener
service exists, it returns the plugin manager immediately (old behavior).config
service, and, if found, ainput_filters
key with an array value. When found, it feeds that value to aZend\ServiceManager\Config
instance and uses that to configure the plugin manager before returning it.