Skip to content

Instantly share code, notes, and snippets.

@xsist10
Created October 6, 2014 19:33
Show Gist options
  • Save xsist10/623dc8dbe24193b690c3 to your computer and use it in GitHub Desktop.
Save xsist10/623dc8dbe24193b690c3 to your computer and use it in GitHub Desktop.
A kernel in a tweet
<?php
// Event Dispatcher
function e($n,$p,$c=0){static $a;@krsort($a[$n]);if($c)$a[$n][$p][]=$c;else foreach($a[$n] as$q)foreach($q as$r)$r($p);}
// Minified Kernel
// function k($r){try{e('dispatch',[$r,&$p]);e('response',$p);}catch(Exception $x){e('error',$x);}}
function k($r) {
try {
e('dispatch',[$r,&$p]);
e('response',$p);
} catch (Exception $x) {
e('error',$x);
}
}
// Do our controller routing here
e('dispatch', 1, function($stack) {
// $stack[0] contains the request
$stack[1] = 'moo';
});
e('response', 1, function($response) {
if (!$response) {
throw new Exception('No page found!');
}
header($_SERVER['SERVER_PROTOCOL'] . ' 200', true, 200);
echo $response;
});
e('error', 1, function($exception) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
echo $exception->getMessage();
});
k('e', $_REQUEST);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment