Created
January 13, 2016 15:57
-
-
Save sasezaki/669e2daa2337caf8e192 to your computer and use it in GitHub Desktop.
An Middleware Builder in a tweet
This file contains hidden or 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 | |
// Minified | |
// class B{function __construct($m){$this->m = $m;} function __invoke($req,$res) {if($this->m)return array_shift($this->m)($req,$res,$this);}} | |
class B{ | |
function __construct($m) | |
{ | |
$this->m = $m; | |
} | |
function __invoke($req,$res) | |
{ | |
if($this->m)return array_shift($this->m)($req,$res,$this); | |
} | |
} | |
require_once __DIR__.'/vendor/autoload.php'; | |
$sender = function($q, $s, $n) { | |
$s = $n($q, $s); | |
echo $s->getBody(); | |
return $s; | |
}; | |
$middlewarex = function($q, $s, $n) { | |
$s->getBody()->write('Hello1'); | |
$s = $n($q, $s); | |
$s->getBody()->write('Hello2'); | |
return $s; | |
}; | |
$app = function($q, $s, $n) { | |
$s->getBody()->write('APP'); | |
return $s; | |
}; | |
$req = Zend\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); | |
$res = new Zend\Diactoros\Response; | |
(new B([$sender, $middlewarex, $app]))($req,$res); // Hello1APPHello2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment