Created
June 25, 2015 07:38
-
-
Save ezimuel/f34b22f347d4a0c985a1 to your computer and use it in GitHub Desktop.
New stratigility example, updated with PR zendframework/zend-stratigility#12
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\Stratigility\MiddlewarePipe; | |
use Zend\Diactoros\Server; | |
require 'vendor/autoload.php'; | |
$app = new MiddlewarePipe(); | |
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); | |
// Injected for all the URL | |
$app->pipe('/', function ($req, $res, $next) { | |
$res->write('Before!'); | |
return $next($req, $res); | |
}); | |
// A specific page | |
$app->pipe('/foo', function ($req, $res, $next) { | |
$res->write('Foo page!'); | |
return $next($req, $res); | |
}); | |
// Injected for all the URL | |
$app->pipe('/', function ($req, $res, $next) { | |
$res->write('After!'); | |
return $next($req, $res); | |
}); | |
$server->listen(); | |
/* | |
Running with "php -S 0.0.0.0:8000" | |
http://localhost:8000/ | |
Before!After!Cannot GET http://localhost:8000/ | |
http://localhost:8000/foo | |
Before!Foo page!After!Cannot GET http://localhost:8000/foo | |
http://localhost:8000/test | |
Before!After!Cannot GET http://localhost:8000/test | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment