Middlewares

Gobline processes and dispatches the request through a set of middlewares.

Default middlewares

Below is the list of the default middlewares, executed in that order:

Gobline\Application\Middleware\RequestMatcherMiddleware

Role

Matches the request with a route.

Requires route data

None.

Adds route data

  • _language
  • _handler

Adds the language for this request. Adds the route's callback handler if any has been defined.

Gobline\Application\Middleware\AuthorizerMiddleware

Role

Authorizes access to the route according to the current user's role.

Requires route data

  • _auth

Adds route data

None.

Gobline\Application\Middleware\FilterMiddleware

Role

Sanitizes and validates route parameters.

Requires route data

  • _filter

Adds route data

None.

Gobline\Application\Middleware\DispatcherMiddleware

Role

Executes the route's callback handler if any has been defined. Dispatches the request to an Action Model.

Requires route data

  • _handler
  • _action

Adds route data

  • _model

Sets the _action's value into _model for the next middlewares.

Gobline\Application\Middleware\JsonRendererMiddleware

Role

If the client request accepts JSON, return the JSON template's content.

Requires route data

  • _model
  • _view

Adds route data

None.

Gobline\Application\Middleware\HtmlRendererMiddleware

Role

Return the content of the HTML template.

Requires route data

  • _model
  • _view
  • _layouts
  • _isSubRequest

_isSubRequest is used in order to disable the rendering of the layouts in the case the request is a sub request (hmvc).

Adds route data

None.

Custom/third-party middlewares

You can create your own custom middleware by adding it into the middleware dispatcher:

<?php
$app
->getDispatcher()
    ->
setMiddlewares([
        
Gobline\Application\Middleware\RequestMatcherMiddleware::class,
        
Gobline\Application\Middleware\AuthorizerMiddleware::class,
        
Acme\Middleware\MyCustomMiddleware::class,
        
Gobline\Application\Middleware\DispatcherMiddleware::class,
        
Gobline\Application\Middleware\JsonRendererMiddleware::class,
        
Gobline\Application\Middleware\HtmlRendererMiddleware::class,
    ]);