Middlewares
In PHP, a middleware is a piece of code that operates between the incoming HTTP request and the corresponding application logic. It allows developers to perform actions before or after the request reaches the controller.
Build a middlewares
You can very easily create you own middlewares.
You could either just duplicate the template file "app/Http/Middlewares/HelloWorld.php", or just create a new one and copy over the template content bellow.
MaplePHP middlewares
MaplePHP comes with a set of middlewares out of the box and this list will grow in time:
Document
You can use the Document middleware to add head, navigation and footer partial.
Meta
Will set up your HTML document's Meta data (title, descriptions), which you can easily modify in your controllers. It will also load in Responder capabilities that add the possibility to communicate seamlessly with the frontend code.
Last modify
Will set up last modify cache functionality.
Session start
Will open up a session.
Logged out
Will check if is public zone (logged out).
Logged in
Will check if is private zone (logged in).
More will come in the future!
Now you can use the middleware just as a controller with the exception for that a middleware has before and after method with the possibility to also add/bind a custom method to the before call.
Last updated