Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 2.08 KB

Middleware.md

File metadata and controls

59 lines (46 loc) · 2.08 KB

Middleware

Directory 'Framework/Middleware' hosts Framework Middleware: Main and Addons.
Directory 'Application/Instance/Middleware' hosts custom Middleware.

Framework Middleware

Middleware for each route is declared in route files i.e. Application/Routes/GETRoutes.php and Application/Routes/POSTRoutes.php.
Use parameter $middleware of method $routes->add(...) in order to declare the Middleware for each route.

$routes->add(
    '/',
    HomeController::class,
    'index',
    // $middleware
    [
        AAAInit::class,
        ApplicationStatusJWT::class,
        UserDetails::class,
        HttpCaching::class => ['interval' => 3600],
        CSP::class,
        SEO::class,
    ],
    [
        'changefreq' => 'daily',
        'priority' => 0.9,
    ]
);

Irrespective of the order set in route files, all framework middleware classes will run in a certain order.
Class Framework\Framework\Libraries\Routes\MiddlewareHandler will enforce this order.


Framework Middleware - Main

  1. AAAInit::class
  2. Admin::class
  3. ApplicationStatusJWT::class
  4. CaptchaEnd::class
  5. CSP::class
  6. CSRFEnd::class
  7. HttpCaching::class
  8. SEO::class
  9. Throttle::class
  10. UserDetails::class

Framework Middleware - Addon

Nothing at the moment.

Custom Middleware

All Middleware must implement Framework\Framework\Middleware\MiddlewareInterface.

Framework middleware runs before any custom/user-defined middleware on both before and after stages.