Download the PHP package muriloamaral/middleware without Composer
On this page you can find all versions of the php package muriloamaral/middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download muriloamaral/middleware
More information about muriloamaral/middleware
Files in muriloamaral/middleware
Package middleware
Short Description Creates middleware layer on Zend Framework 2.
License
Homepage https://github.com/muriloacs/Middleware
Informations about the package middleware
Middleware
Creates middleware layer on Zend Framework 2. Useful when it's necessary to make some work between route and controller dispatch phases.
Installation
With composer
Add this project in your composer.json
:
Now tell composer to download Middleware by running the command:
Post installation
Enabling it in your config/application.config.php
file.
Configuration
On your config file set your global and local middlewares. For instance:
Usage
Define your middleware classes:
Global scope
Middlewares on global scope will be executed everytime a request is made.
Local scope
Middlewares on local scope will be executed only if the current controller declares a middleware.
P.S: local middlewares are executed after global middlewares.
In this case, my.first.middleware
and my.second.middleware
will be always executed no matter what route is being called. Whereas my.third.middleware
will be executed only when
Application\Controller\IndexController is being called. Thus, if we access Application\Controller\IndexController first, second and third middlewares will be executed.
Advanced usage
Inject Service Locator
It's also possible to access ServiceManager within your middleware classes. It's only necessary to implement ServiceLocatorAwareInterface. For instance:
Abstract Service Factory
If you don't want to declare middlewares inside your service manager config key, you can use the abstract service factory provided by us.
-
Define your middleware class, you need to implement
Middleware\MiddlewareInterface
. -
Configure your middleware
- Configure the abstract service factory
Configuration
You can provide any callable as a middleware name. Such as functions, static methods and so on. For instance: