Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Last active May 10, 2018 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/2fe892d36c54811e0cb60ba9b5db5c29 to your computer and use it in GitHub Desktop.
Save Ocramius/2fe892d36c54811e0cb60ba9b5db5c29 to your computer and use it in GitHub Desktop.
<?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;
});
Should print [16, 23, 30]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment