function testPrefix()
 {
     $routes = new RouteCollection();
     $routeBuilder = new RouteBuilder('/', $routes);
     $routeBuilder->prefix('/foo', function (RouteBuilder $routes) {
         $routes->http('/bar', ['name' => 'bar']);
     });
     $this->assertEquals('/foo/bar', $routes->getByName('bar')->getPath());
 }
Exemple #2
0
 function testSchemes()
 {
     $routes = new RouteCollection();
     $route = new Route('/foo/{id}/bar/{name}', '');
     $route->setSchemes(['https']);
     $routes->add($route);
     $context = RequestContext::create();
     $context->setScheme('https');
     $this->assertEquals(['https'], $route->getSchemes());
     $this->assertEquals('https', $context->getScheme());
     $matcher = new Matcher($context);
     $this->assertEquals($route, $matcher->match('/foo/100/bar/steven', $routes));
     $context->setScheme('http');
     $this->setExpectedExceptionRegExp('Slince\\Routing\\Exception\\RouteNotFoundException');
     $matcher->match('/foo/100/bar/steven', $routes);
 }
Exemple #3
0
 /**
  * 根据action生成url
  * @param $action
  * @param array $parameters
  * @param bool $absolute
  * @return string
  * @throws RouteNotFoundException
  */
 function generateByAction($action, $parameters = [], $absolute = false)
 {
     $route = $this->routes->getByAction($action);
     if (is_null($route)) {
         throw new RouteNotFoundException(sprintf('Action "%s" not defined.', $action));
     }
     return $this->getGenerator()->generate($route, $parameters, $absolute);
 }