Middlewares

Introduction

Middleware provides a convenient mechanism for inspecting and filtering HTTP requests coming into your application. All middleware is registered in the app/middlewares directory.

Creating Middlewares

To generate the middleware you can use the nailer command:

php nailer make:middleware HomeMiddleware

Using

Middlewares must be specified in the route to use it.

$Route->Add()
    ->get('/home')
    ->controller(HomeController::class)
    ->action('Index')
    ->middleware(HomeMiddleware::class);

Here is an example of middleware that displays 'Hello World!'

namespace App\Middlewares;

class HomeMiddleware
{
    public function __construct()
    {
        echo 'Hello World!';
    }
}