-
Framework
-
Router
- mu - A tweet-sized PHP micro-router.
| <?php | |
| namespace A; | |
| use A\Container\Builder as ContainerBuilder; | |
| class App { | |
| public $root; /** root directory given when initilizated */ | |
| public $container; /** an array-like object to retrieve services from */ |
| <?php | |
| class App { | |
| public $queue = []; | |
| public $routes = []; | |
| public $container; | |
| public $resolver; |
| <?php | |
| class Router implements RouterInterface { | |
| private $root; | |
| private $routes = []; | |
| public function __construct($root) { | |
| $this->root = $root; | |
| } |
| <?php | |
| class Emitter implements EmitterInterface { | |
| private $listeners = []; | |
| private $order = PHP_INT_MAX; | |
| public function on($event, callable $listener, $priority=0) | |
| { | |
| if (array_key_exists($event, $this->listeners) === false) { | |
| $this->listeners[$event] = new \SplPriorityQueue; |
| <?php | |
| interface ContainerInterface { | |
| function get($key, array $arguments=[]); | |
| function has($key); | |
| } | |
| /** | |
| * Dependency Injection Container. | |
| */ |
| <?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 // 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 | |
| $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 | |
| class GroupIterator implements Iterator | |
| { | |
| protected $keyfunc; | |
| protected $iter; | |
| protected $key = null; | |
| protected $value = null; |