Skip to content

Middleware

AngelNovo edited this page Aug 14, 2024 · 2 revisions

Usage

use lib\middleware\Middleware;

Creating the default auth middlewares

/*
 define_essentials() will create the following middlewares
 Simple-Auth, Bearer-Auth
*/
Middleware::define_essentials();

Define custom middlewares

/**
 @param $class must be with the following notation: ClassName::class
 The function to verify the middleware must be static
*/
Middleware::define(string $key, $class, string $function);

Effects of middleware in a route or set of routes

Notation

Middleware::on(string $key, callable $closure_containing_routes);

Example

Middleware::on('Simple-Auth', function() {
    Route::Get('/', Index::class, 'GetIndexView');
});