public function testNestedRoutesInsideParamCallback() { $app = new Bullet\App(); $app->path('admin', function ($request) use($app) { $app->path('client', function ($request) use($app) { $app->param('int', function ($request, $id) use($app) { $app->path('toggleVisiblity', function ($request) use($app, $id) { $app->path('item', function ($request) use($app, $id) { $app->get(function ($request) use($app) { return "deep"; }); }); }); }); }); }); $result = $app->run(new Bullet\Request('GET', '/admin/client/1/toggleVisiblity/item')); $this->assertEquals('deep', $result->content()); }
function testOptionsHeaderForParamPaths() { $app = new Bullet\App(); $req = new Bullet\Request('OPTIONS', '/test/this_is_a_slug'); $app->path('test', function ($request) use($app) { $app->param('slug', function ($request, $param) use($app) { $app->get(function ($request) { return 'GET'; }); $app->post(function ($request) { return 'POST'; }); }); }); $res = $app->run($req); $this->assertEquals('OK', $res->content()); $this->assertEquals('GET,POST,OPTIONS', $res->header('Allow')); }
/** * Register the callback for the given parameter * * @param string $param * @param \Closure $callback * @return $this */ public function registerParameter($param, \Closure $callback) { $this->app->param($param, $callback); return $this; }