Add New Middleware

Last updated: 27.02.2020

If you are not familiar with the concept of middleware, please read the Slim framework documentation first. With middleware, you can add some logic that is added to the live cycle of the application. Some examples of uses for middleware are:

The concept of middleware is a bit harder to understand, but to add middleware with a plugin is pretty easy with the method addNewMiddleware():

public static function addNewMiddleware()
    return array(
        'classname' => 'Plugins\MyPlugin\MyMiddleware', 
        'params' => false

The method returns an array again and accepts two values:

You can create a new file called MyMiddleware.php in your plugin and add a middleware logic like this:


namespace Plugins\MyPlugin;

class MyMiddleware 
    public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, $next)
        // do something here 
        return $next($request, $response);      

The support for middleware in TYPEMILL is pretty basic right now, and it has some limitations. The most important limitation:

The middleware support in TYPEMILL will be improved in the future. For now, only use it if you really know what you wanna do. You can also add a new issue in GitHub, if you need a specific feature.