Last active
May 10, 2018 21:50
-
-
Save Ocramius/2fe892d36c54811e0cb60ba9b5db5c29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Zend\Diactoros\Response; | |
use Zend\Diactoros\Server; | |
use Zend\Stratigility\MiddlewarePipe; | |
use function Zend\Stratigility\middleware; | |
require 'vendor/autoload.php'; | |
$app = new MiddlewarePipe(); | |
$server = Server::createServer([$app, 'handle'], $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); | |
$app->pipe(middleware(function ($req, $handler) { | |
$calls = $req->getAttribute('calls') ?? []; | |
$calls[] = __LINE__; | |
return $handler->handle($req->withAttribute('previousCalls', $calls)); | |
})); | |
$app->pipe(middleware(function ($req, $handler) { | |
$calls = $req->getAttribute('calls') ?? []; | |
$calls[] = __LINE__; | |
return $handler->handle($req->withAttribute('calls', $calls)); | |
})); | |
$app->pipe(middleware(function ($req, $handler) { | |
$calls = $req->getAttribute('calls') ?? []; | |
$calls[] = __LINE__; | |
$response = new Response(); | |
$response->getBody()->write(json_encode($calls); | |
return $response; | |
})); | |
$server->listen(function ($req, $res) { | |
return $res; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should print [16, 23, 30] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment