-
Framework
-
Router
- mu - A tweet-sized PHP micro-router.
| <?php | |
| $started = false; | |
| function start() { | |
| global $started; | |
| if ($started) { | |
| print("Already started\n"); | |
| return; |
| <?php | |
| interface Module | |
| { | |
| function start(); | |
| function stop(); | |
| function buildContainer(Container $container); | |
| } |
| <?php | |
| // This class I used several times before: | |
| // @see https://gist.github.com/jm42/e7e788d7e257ce1f93c7 | |
| // @see https://gist.github.com/jm42/4fc873e91b3835ade45f | |
| class InputFilter implements \ArrayAccess { | |
| private $input; | |
| private $cache = []; |
| <?php | |
| class Headers implements ArrayAccess { | |
| private static $headers = array( | |
| 'Accept', | |
| 'Accept-Charset', | |
| 'Accept-Language', | |
| 'Accept-Encoding', | |
| 'Authorization', | |
| 'Cache-Control', |
| <?php | |
| class GroupIterator implements Iterator | |
| { | |
| protected $keyfunc; | |
| protected $iter; | |
| protected $key = null; | |
| protected $value = null; |
| <?php | |
| $container['db.config'] = array( | |
| 'file' => __DIR__ . '/../tmp/mvc.db', | |
| 'init' => function(PDO $pdo) { | |
| $pdo->exec('CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255))'); | |
| $pdo->exec('INSERT INTO user (id, name) VALUES (1, "John Doe")'); | |
| $pdo->exec('INSERT INTO user (id, name) VALUES (2, "Jane Doe")'); | |
| }, | |
| ); |
| <?php // php -dallow_url_include=1 c.php | |
| // Compressed 122 bytes | |
| // class C extends ArrayObject { function __get($i) { $s = $this[$i]; $s instanceof Closure && $s = $s($this); return $s; } } | |
| class C extends ArrayObject { | |
| function __get($i) { | |
| $s = $this[$i]; | |
| $s instanceof Closure && $s = $s($this); | |
| return $s; |
| <?php | |
| // Compressed 138 bytes | |
| // function m($s,$t,$r){foreach($s as$p){if(!isset($t[$p]))break;$t=$t[$p];}foreach($r as$e)if ($e[1]?:$p==$p&&is_a($t,$e[0]))return[$e,$t];} | |
| function m($s, $t, $r) { | |
| foreach ($s as $p) { | |
| if (!isset($t[$p])) break; | |
| $t = $t[$p]; | |
| } |
| <?php | |
| interface ContainerInterface { | |
| function get($key, array $arguments=[]); | |
| function has($key); | |
| } | |
| /** | |
| * Dependency Injection Container. | |
| */ |