public static function expand() { $class = get_called_class(); $routeset = new \Roller\RouteSet(); $routeset->add('/', $class . ':indexAction'); $routeset->add('/collection.json', $class . ':jsonAction'); $routeset->add('/collection.yml', $class . ':yamlAction'); return $routeset; }
function test() { $routes = new Roller\RouteSet(); $routes->add('/blog/:year/:month', function () { return 'Yes'; }, array('year' => '\\d')); $routes->compile(); $dumper = new Roller\Dumper\ConsoleDumper(); ob_start(); $dumper->dump($routes); ob_end_clean(); }
function testPHPDumper() { $routes1 = new Roller\RouteSet(); $routes2 = new Roller\RouteSet(); $routes1->add('/item', function () { return 'item'; }); $routes2->add('/subitem', function () { return 'subitem'; }); $routes1->mount('/item', $routes2); $dumper = new Roller\Dumper\PhpDumper(); $code = $dumper->dump($routes1); $cRoutes = eval($code); $router = new Roller\Router($cRoutes); $r = $router->dispatch('/item'); is('item', $r()); $r = $router->dispatch('/item/subitem'); is('subitem', $r()); }
<?php require 'tests/bootstrap.php'; $routes = new Roller\RouteSet(); $routes->add('/blog/:year/:month', function ($year, $month) { return 'Yes'; }, array('year' => '\\d+')); $routes->add('/blog/:id', function ($id) { return $id; }, array('id' => '\\d+')); $routes->compile(); $dumper = new Roller\Dumper\ConsoleDumper(); $dumper->dump($routes);