I’m currently using ZF3 with a large code base and I want to start writing middleware. As of Zend/mvc 3.1 you can create an array of middleware to be piped for a given route/path in the configuration; great feature. See the following link for some reference; https://www.jamestitcumb.com/posts/middleware-in-zend-mvc. However, I have not seen the capability to specify a set of middleware to be run on every request (ex. ip filter, CORS, auth, logging etc.) like you can in Zend Expressive. One can accomplish this in Zend Expressive by piping middleware before the routing middleware; makes sense. Does this capability exist in ZF3?
No, this feature does not exist. It can be done within event listeners by having the listener pull the request from the event, pass it to the psr7bridge to convert it, and then dispatch your middleware or pipeline with it. If you do, I’d suggest passing the MvcEvent as a request attribute.
Do you know if there have been any updates to ZF 3 that would allow me to implement what I previously suggested? You did give me an alternative option about a year ago, which I have contemplated, but I was just wondering if this functionality has been added yet.
Nope, not yet. Feel free to send a pull request if you’re interested, though!
matthew, How to call middleware PSR-15 within event listeners in zend framework 3 (zend-mvc)? I have created topic at this forum How to call middleware PSR-15 within event listeners in zend framework 3 (zend-mvc)? . Can you give me some hints?