Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Created June 25, 2015 07:38
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 ezimuel/f34b22f347d4a0c985a1 to your computer and use it in GitHub Desktop.
Save ezimuel/f34b22f347d4a0c985a1 to your computer and use it in GitHub Desktop.
New stratigility example, updated with PR zendframework/zend-stratigility#12
<?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