Skip to content

Commit

Permalink
Simplify middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
aredridel committed Mar 22, 2012
1 parent abbb10d commit 3587379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
9 changes: 0 additions & 9 deletions App.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
namespace Fw;

abstract class App extends Middleware {
public function dispatch($env) {
$req = Request::createInstance($env['params'], $env['server']);
$res = Response::createInstance();

$this->route($req, $res);

}

abstract protected function route(Request $req, Response $res);

protected function subPath($path) {
return $this->basePath() .$path;
Expand Down
13 changes: 7 additions & 6 deletions Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

abstract class Middleware {

abstract public function __invoke($env, $next = null);
abstract public function __invoke($req, $res, $next = null);

static private $stack;

Expand All @@ -13,16 +13,17 @@ static public function apply(Middleware $middleware) {
}

static public function run() {
$env = array('params' => $_REQUEST, 'server' => $_SERVER);

$req = Request::createInstance($_REQUEST, $_SERVER);
$res = Response::createInstance();

$stack =& self::$stack;

$next = function($env) use (&$stack, &$next) {
$next = function($req, $res) use (&$stack, &$next) {
$current = array_shift($stack);
return $current($env, $next);
return $current($req, $res, $next);
};

return $next($env);
return $next($req, $res);

}

Expand Down

0 comments on commit 3587379

Please sign in to comment.