Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Last active May 10, 2018
Embed
What would you like to do?
<?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