Abdul Malik Ikhsan has a post to his site showing how you can integrate the concept of middleware in to the Zend MVC Component of the Zend Framework. Middleware has come into its own with the acceptance of of the PSR-7 standard and several frameworks adopting its structure for request/response handling.
zend-mvc 2.7.0 is coming, beside of the forward compatibility with V3 components, there is new middleware listener that allow us to do Dispatching PSR-7 middleware. The middleware can be an invokable class with __invoke() method.
He shows how, starting with a new project, to create the middleware class (in this case HomeAction
) and the __invoke
function. He then adds in the "home" route to the module configuration and points it at this HomeAction
class. He registers it in the service manager as an InvokableFactory
and it magically works. From there he refactors to allow the middleware to work with the ViewModel and change things like templates and variable values.