Created
October 7, 2015 18:34
-
-
Save mrferos/96a7455d70e990a9b376 to your computer and use it in GitHub Desktop.
Playing with stratigility
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 | |
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