Technically speaking, a middleware is a callable that accepts three arguments:
It can do whatever is appropriate with these objects. The only hard requirement is that a middleware MUST return an instance of \Psr\Http\Message\ResponseInterface. Each middleware SHOULD invoke the next middleware and pass it Request and Response objects as arguments.
Different frameworks use middleware differently. Harmony adds middleware as concentric layers surrounding your core application. Each new middleware layer surrounds any existing middleware layers. The concentric structure expands outwardly as additional middleware layers are added.
The last middleware layer added is the first to be executed.
When you run the Harmony application, the Request and Response objects traverse the middleware structure from the outside in. They first enter the outer-most middleware, then the next outer-most middleware, (and so on), until they ultimately arrive at the Harmony application itself. After the Harmony application dispatches the appropriate route, the resultant Response object exits the Harmony application and traverses the middleware structure from the inside out. Ultimately, a final Response object exits the outer-most middleware, is serialized into a raw HTTP response, and is returned to the HTTP client.
Middleware is a callable that accepts three arguments: a Request object, a Response object, and the next middleware. Each middleware MUST return an instance of \Psr\Http\Message\ResponseInterface.
Create Middleware using Artisan Command
> php artisan make:middleware SomeMiddleware
File created (SomeMiddleware.php) in app/Middleware/SomeMiddleware.php
This example middleware is a Closure.
You may add middleware to a Harmony application, to an individual Harmony application route or to a route group. All scenarios accept the same middleware and implement the same middleware interface.
When you create middleware with Artisan Command then middleware will be registered in app/config/app.middleware.php
if you need further explanation, you can read the documentation in Slim Framework - Middleware