<?php
require 'vendor/autoload.php';
$app = new \Slim\App();
// Executed last as it's first in (FILE)
$app->add(function ($request, $response, $next) {
// Execute the routes first
$response = $next($request, $response);
// Append the result from routes
$response->getBody()->write(' Baz ');
return $response;
});
$app->get('/', function ($req, $res, $args) {
echo ' Bar ';
});
// Executed first as it's last in (LIFE)
$app->add(function ($request, $response, $next) {
$response->getBody()->write(' Foo ');
return $next($request, $response);
});
$app->run();
Created
February 27, 2016 16:34
-
-
Save betweenbrain/d337caa01b2067f7b8aa to your computer and use it in GitHub Desktop.
Slim 3 Middleware Execution Order Example (last in, first executed)
Good example. It's not immediately obvious from the Slim docs on how the sequence of the middlewares is handled.
Great explanation, thank you
Thanks, was very useful explanation!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, I thought there was something wrong with my middlewares. it's executed in an ascending order.