private function group(array $config) { foreach ($config as $path => $val) { $this->router->group($path, function (Router $r) use($val) { (new ConfigRouter($r))->routeByConfig($val); }); } }
public function testStack() { $r = new Router(); $r->stack('Fixture\\FirstMiddleware'); $r->stack('Fixture\\SecondMiddleware'); $r->get('/', function ($req) { return $req->query->get('content', '') . ' /'; }); $r->group('/g', function ($r) { $r->stack('Fixture\\ThirdMiddleware'); $r->get('/', function ($req) { return $req->query->get('content', '') . ' /g/'; }); }); $res = $r->run(Request::create('/')); $this->assertEquals(200, $res->getStatusCode()); $this->assertEquals(' b1 b2 / a2 a1', $res->getContent()); $res = $r->run(Request::create('/g/')); $this->assertEquals(200, $res->getStatusCode()); $this->assertEquals(' b1 b2 b3 /g/ a3 a2 a1', $res->getContent()); }
public function testSeparateRouter() { $child = new Router(); $child->get('/', function () { return ''; }); $r = new Router(); $r->group('/user', $child); $req = Request::create('/user/'); $res = $r->run($req); $this->assertEquals(200, $res->getStatusCode()); $req = Request::create('/'); $res = $child->run($req); $this->assertEquals(200, $res->getStatusCode()); $req = Request::create('/user/'); $res = $child->run($req); $this->assertEquals(404, $res->getStatusCode()); $req = Request::create('/'); $res = $r->run($req); $this->assertEquals(404, $res->getStatusCode()); }