The process of using the Middleware

Hello everyone

I read the MVC-Middleware document and run simple middleware to check user authentication.

First, I understand, after running the middleware step in the next step handler should run as a single action controller, and AbstractActionController is not acceptable in the handler, and it child of Psr RequestHandlerInterface

Now I have some questions before using this method in my modules:

1- Is it’s the true way and I understand true?
2- If it’s true, which one is better? Use middleware and Psr handler or use Laminas controller as a child of AbstractActionController, which one is better and more powerful?
3- If I use Laminas controller, for some middleware use-case (like checking user access token) what should I do? call service at the start of each action?

Before reading MVC-Middleware I thought, I can write some general middleware to check User, ACL, or RBAC, request params, security, and some other dependency. But I do not know what is the best way to do this now

Please share your idea and experience with me

Do you have any idea about this?

laminas-mvc-middleware could be used to run middleware pipes, but it can not be used as a middleware in front of a controller. As such, middleware pipe is an alternative to the controller.

1 Like

Thank you for your reply
Then if I use middleware, I should use (( middleware-pipe / handler)) Instead of the controller. But if I use middleware-pipe I don’t have access to all MVC controller plugins, service, view manager, and AbstractController, then I lost laminas MVC power. and should write large router

According to the cause, Is it correct to use middleware?

I should ask it because we have to plan to start some new projects in 2022, based on laminas-MVC or mezzio and I have to have a technical answer for my team to questions like this