Skip to content

Instantly share code, notes, and snippets.

@jmoyers
Created August 26, 2011 22:50
Show Gist options
  • Save jmoyers/1174619 to your computer and use it in GitHub Desktop.
Save jmoyers/1174619 to your computer and use it in GitHub Desktop.
$stack = function () use ($app) {
$args = func_get_args();
return function() use ($app, $args){
$req = $app['request'];
$res = new \Symfony\Component\HttpFoundation\Response;
$cb = false;
foreach($args as $mw){
$cb = function($req, $res) use ($mw, $cb){
return $cb($req, $res, function($req, $res, $cb){
if( is_instance($mw, 'CallableMiddleware') ) {
return $mw->call($req, $res, $cb);
} else {
return $mw($req, $res, $cb);
}
});
}
}
return $cb($req, $res);
}
}
$reqUser = function($req, $res, $cb){
if ($req['user']) return $cb($req, $res);
$res->setForbidden();
}
$app->get('/', $stack($reqUser, function($req, $res){
return "Hello world";
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment