Create middleware to replace slim.after.router hook

Hi all,

i’m updating my app from slim 2 to slim 3. I used the hook slim.after.router but now, on slim3, hooks were replaced by middlewares.
Anyone can give me an exmple of how can i create a middleware to run like slim.after.router hook?

thanks

Set the setting determineRouteBeforeAppMiddleware to true

You can then write middleware where the current route is available in $request->getAttribute('route');

Slim 2 documentation said:

This hook is invoked after the router is dispatched, before the Response is sent to the client, and after output buffering is turned off. This hook is invoked once during the Slim application lifecycle.

@akrabat, but how can I code just before the response is sent to the client?

$app->add(function ($request, $response, $next) {
    $response = $next($request, $response);
    $response = $response->withHeader('X-Clacks-Overhead', 'GNU Terry Pratchett');
    return $response;
});