Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created September 2, 2012 03:50
Show Gist options
  • Save msonnabaum/3594689 to your computer and use it in GitHub Desktop.
Save msonnabaum/3594689 to your computer and use it in GitHub Desktop.
<?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