コード例 #1
0
ファイル: RoutesMatcherTest.php プロジェクト: weew/router
 public function routes_provider()
 {
     $router = new Router();
     $router->get('/shop/{name}', 'foo');
     $router->get('/category/{name}/item/{id}/{alias?}', 'foo');
     $router->post('/category/{name}/item/{id}', 'bar');
     $router->delete('/country/{country}/city/{city}/{any}', 'foo');
     $router->delete('country/{country}/city/{city}/{any?}', 'bar');
     $router->put('yolo/{what}/swag/{huh?}', 'bar');
     $routes = $router->getRoutes();
     return [[$routes, HttpRequestMethod::GET, new Url('http://foo.bar/category'), false, [], null], [$routes, HttpRequestMethod::GET, new Url('http://foo.bar/category/foo/item/bar'), true, ['name' => 'foo', 'id' => 'bar', 'alias' => null], 'foo'], [$routes, HttpRequestMethod::GET, new Url('http://foo.bar/category/foo/item/bar/swag'), true, ['name' => 'foo', 'id' => 'bar', 'alias' => 'swag'], 'foo'], [$routes, HttpRequestMethod::POST, new Url('http://foo.bar/category/foo/item/bar/swag'), false, [], null], [$routes, HttpRequestMethod::POST, new Url('http://foo.bar/category/foo/item/bar'), true, ['name' => 'foo', 'id' => 'bar'], 'bar'], [$routes, HttpRequestMethod::DELETE, new Url('http://foo.bar/country/foo/city/bar/yolo/swag'), true, ['country' => 'foo', 'city' => 'bar', 'any' => 'yolo/swag'], 'foo'], [$routes, HttpRequestMethod::DELETE, new Url('http://foo.bar/country/foo/city/bar'), true, ['country' => 'foo', 'city' => 'bar', 'any' => null], 'bar'], [$routes, HttpRequestMethod::PUT, new Url('yolo/foo/swag/bar'), true, ['what' => 'foo', 'huh' => 'bar'], 'bar'], [$routes, HttpRequestMethod::PUT, new Url('yolo/foo/swag'), true, ['what' => 'foo', 'huh' => null], 'bar']];
 }
コード例 #2
0
 function it_runs(IInput $input, IOutput $output)
 {
     $router = new Router();
     $router->addFilter('filter', function () {
     });
     for ($i = 0; $i < 15; $i++) {
         $router->get('/some/path', 'value');
     }
     for ($i = 0; $i < 15; $i++) {
         $router->group()->get('/another/path', 'value');
     }
     $router->enableFilter('filter');
     $this->run($input, $output, $router);
 }
コード例 #3
0
ファイル: RouterTest.php プロジェクト: weew/router
 public function test_with_unresolved_parameter()
 {
     $router = new Router();
     $router->get('foo/{value}', function () {
     });
     $route = $router->match(HttpRequestMethod::GET, new Url('foo/bar'));
     $this->assertTrue($route instanceof IRoute);
     $this->assertEquals('/foo/{value}', $route->getPath());
     $router->addResolver('value', function () {
         return null;
     });
     $route = $router->match(HttpRequestMethod::GET, new Url('foo/bar'));
     $this->assertNull($route);
     $router->addResolver('value', function () {
         return true;
     });
     $route = $router->match(HttpRequestMethod::GET, new Url('foo/bar'));
     $this->assertTrue($route instanceof IRoute);
     $this->assertEquals('/foo/{value}', $route->getPath());
 }