Exemple #1
0
 private function group(array $config)
 {
     foreach ($config as $path => $val) {
         $this->router->group($path, function (Router $r) use($val) {
             (new ConfigRouter($r))->routeByConfig($val);
         });
     }
 }
Exemple #2
0
 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());
 }
Exemple #3
0
 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());
 }