Created
September 2, 2012 03:50
-
-
Save msonnabaum/3594689 to your computer and use it in GitHub Desktop.
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 | |
class Kernel { | |
function handle() {} | |
} | |
class DrupalApp { | |
function __construct() { | |
$this->kernel = new Kernel(); | |
} | |
function call($request) { | |
print "Generating response!\n"; | |
return $this->kernel->handle($request); | |
} | |
} | |
class DrupalAppCache { | |
function __construct($app) { | |
$this->app = $app; | |
} | |
function call($request) { | |
if ($cached_response = $this->isCached($request)) { | |
print "Returning cached response!\n"; | |
return $cached_response; | |
} | |
else { | |
print "Cache miss! Calling through!\n"; | |
$this->app->call($request); | |
} | |
} | |
function isCached($request) { | |
return FALSE; | |
} | |
} | |
$apps = array(); | |
if ($cache_enabled = TRUE) { | |
$apps[] = 'DrupalAppCache'; | |
} | |
$stack = array(); | |
foreach ($apps as $app) { | |
$stack[] = function ($next_app) use ($app) { | |
return new $app($next_app); | |
}; | |
} | |
$request = array(); | |
print array_reduce(array_reverse($stack), function ($a, $e) { | |
$a = $a ?: new DrupalApp(); | |
return $e($a); | |
})->call($request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment