Add New Middleware

If you are not familiar with the concept of middleware, please read the documentation of slim first. With middleware you can add some logic that is added to the live cycle of the application. Some examples 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 and array again and accepts to values:

You can create a new file 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 of 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 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 miss anything.