/**
  * @return Router
  */
 protected function getRouter()
 {
     $router = new Router();
     $router->setMethodOverride('_method');
     $router->addRoute(new FinalRoute('result', new UrlTemplate(['method' => 'delete', 'path' => '/item/'])));
     return $router;
 }
Esempio n. 2
0
 /**
  * @return Router
  */
 protected function getRouter()
 {
     $router = new Router();
     $siteRoutes = new RouteGroup(new UrlTemplate(['scheme' => 'http', 'host' => 'example.com']));
     $siteRoutes->addRoute(new FinalRoute('homepageResult', new UrlTemplate(['path' => '/'])));
     $siteRoutes->addRoute(new FinalRoute('itemsResult', new UrlTemplate(['path' => '/items/{itemId}/'])));
     $siteRoutes->addRoute(new FinalRoute('catsResult', new UrlTemplate(['path' => '/cats/{catId:\\d+:}/'])));
     $siteRoutes->addModifier((new LanguagePrefixRouteModifier('langModifier'))->setLanguagesIds(['en', 'de', 'fr'])->setDefaultLanguage('en'));
     $siteRoutes->addModifier(new MobileHostRouteModifier('mobileHostModifier'));
     $router->addRoute($siteRoutes);
     $router->addRoute(new AdminRoute('adminResult'));
     return $router;
 }
Esempio n. 3
0
 /**
  *
  */
 public function testBuildingUrls()
 {
     $router = new Router();
     $router->addRoute(new FinalRoute('homepageResult', (new UrlTemplate())->setScheme('http')->setPathTemplate('/')->setHostTemplate('example.com')));
     $router->addRoute(new FinalRoute('itemListResult', (new UrlTemplate())->setScheme('http')->setPathTemplate('/items/')->setHostTemplate('example.com')));
     $router->addRoute(new FinalRoute('singleItemResult', (new UrlTemplate())->setScheme('http')->setPathTemplate('/items/{itemId}/')->setHostTemplate('example.com')));
     $this->assertEquals('http://example.com/', $router->getUrl('homepageResult')->assemble());
     $this->assertEquals('http://example.com/items/', $router->getUrl('itemListResult')->assemble());
     $this->assertEquals('http://example.com/items/1/', $router->getUrl('singleItemResult')->setParameter('itemId', 1)->assemble());
 }
Esempio n. 4
0
 /**
  *
  */
 public function testAdvancedModifiers()
 {
     $router = new Router();
     $siteRouteGroup = new RouteGroup(new UrlTemplate(['host' => 'site.com']));
     $siteRouteGroup->addModifier((new PrefixModifier())->setPrefix('/site/'));
     $siteMyRouteGroup = new RouteGroup();
     $siteMyRouteGroup->addModifier(new PrefixMyRouteModifier());
     $siteMyRouteGroup->addRoute(new FinalRoute('routeResult', new UrlTemplate(['path' => '/orders/'])));
     $siteRouteGroup->addRoute($siteMyRouteGroup);
     $router->addRoute($siteRouteGroup);
     $router->doMatch(RequestContextFactory::createFromUrl('http://site.com/site/my/orders/'));
     $this->assertEquals('http://site.com/site/my/orders/', $router->generateUrl('routeResult'));
 }
Esempio n. 5
0
 public function testActionOverride()
 {
     $router = new Router();
     $this->expectOutputString('barfoobar');
     $router->when('/{foo}/{bar}/')->then('ok', function ($foo, $bar) {
         return $foo . $bar;
     })->post(function ($bar, callable $GET) {
         echo $bar;
         return $GET;
     });
     $_SERVER['REQUEST_URI'] = '/foo/bar/';
     $_SERVER['REQUEST_METHOD'] = 'POST';
     echo $router(ServerRequestFactory::fromGlobals());
 }