How to use InputFilter in middleware Mezzio?

Hi guys! I’m trying to make a middleware with InputFilter in mezzio however I have had the following error:

“Unable to resolve service “App\InputFilter\UserInputFilter” to a factory; are you certain you provided it during configuration?”

It only fails in the middleware if I use InputFilter in the handler it works correctly, I’m based on the configuration indicated by the site.

Has anyone had the same problem?

Input filters must be retrieved from the InputFilterPluginManager, so inside your Middleware/Handler factory, you’d first make a call to $inputFilterManager = $container->get(InputFilterPluginManager::class); and your filter would be available to pass to your Middleware constructor like return new MyMiddleware($inputFilterManager->get(MyInputFilter::class)); - I hope that’s helpful.

1 Like

Thank you so much Jorge, it was a great help to me! :slightly_smiling_face:

The required code example for the factory is included in the documentation which you have linked: