Skip to content

Application#middleware(): the new capability to create middlewares #5

@gstsdev

Description

@gstsdev

In the next major version of Armor, a interesting feature could be implemented: the capability to create middlewares to the application.

The method that would be used to define these middlewares would be named Application#middleware(). It would work like this:

// ...
$app = ...;

$app->middleware(function(Request $req, Response $res) {
    // ...
});

$app->middleware('auth', function(Request $req, Response $res) {
   // ...
});

That is, this method could receive:

  • The callback function, that for every request would be one of the first functions that would manipulate the request and response objects, what create the need of adapting these objects to be "extensible" (receive external variables and/or functions);
    • $app->middleware(function(Request $req, Response $res) {
         $req->user = auth_user_from_req($req);
         $res->render = function() { // ... };
      }); 
  • And, optionally, a string that would identify this specific middleware, if these can be implemented "globally", or you want to just use a specific middleware, for example;
    • $app->middleware('auth', function(...) { ... });
      
      $app->get('/dashboard', function(...) { ... })->preprocess('auth');

It's a feature to think about.

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.0.0Action or feature to the 2.0.0 versionenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions