Skip to content

Instantly share code, notes, and snippets.

@mrferos
Created October 7, 2015 18:34
Show Gist options
  • Save mrferos/96a7455d70e990a9b376 to your computer and use it in GitHub Desktop.
Save mrferos/96a7455d70e990a9b376 to your computer and use it in GitHub Desktop.
Playing with stratigility
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use \Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
$app = new \Zend\Stratigility\MiddlewarePipe();
$app->pipe('/', function(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) {
$body = $response->getBody();
$body->write('This is a message');
if (!is_null($next)) {
return $next($request, $response);
}
});
$app->pipe(function(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
$body = $response->getBody();
if (strstr((string)$body, 'message')) {
$body->write(' more message');
}
if (!is_null($next)) {
return $next($request, $response);
}
});
$server = \Zend\Diactoros\Server::createServer(
$app,
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$server->listen();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment