Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function build(Url $url, UrlBuilder $urlBuilder)
 {
     $domain = $urlBuilder->useParameter('_domain');
     $url->setHost($domain);
     $isMobile = $urlBuilder->useParameter('_isMobile');
     if ($isMobile === true) {
         $url->setHost('m.' . $url->getHost());
     }
     if ($devBranch = $urlBuilder->useParameter('_devBranch')) {
         $url->setHost($devBranch . '.debug.' . $url->getHost());
     }
     parent::build($url, $urlBuilder);
 }
Ejemplo 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;
 }
Ejemplo n.º 3
0
 /**
  * 
  */
 public function testRoutesMatchTest()
 {
     $routeGroup = new RouteGroup();
     $routeGroup->addRoute(new FinalRoute('routeResult1', new UrlTemplate(['host' => 'example.com', 'path' => '/list/'])));
     $routeGroup->addRoute(new FinalRoute('routeResult2', new UrlTemplate(['host' => 'example.com'])));
     $routeGroup->addRoute(new FinalRoute('routeResult3', new UrlTemplate(['host' => 'example.ua', 'path' => '/list/'])));
     $routeMatch1 = $routeGroup->doMatch(RequestContextFactory::createFromUrl('http://example.com/list/'));
     $this->assertNotEmpty($routeMatch1);
     $this->assertEquals('routeResult1', $routeMatch1->getRouteResult());
     $routeMatch2 = $routeGroup->doMatch(RequestContextFactory::createFromUrl('http://example.com/'));
     $this->assertNotEmpty($routeMatch2);
     $this->assertEquals('routeResult2', $routeMatch2->getRouteResult());
     $routeMatch3 = $routeGroup->doMatch(RequestContextFactory::createFromUrl('http://example.ua/list/'));
     $this->assertNotEmpty($routeMatch3);
     $this->assertEquals('routeResult3', $routeMatch3->getRouteResult());
 }
Ejemplo 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'));
 }