Ejemplo n.º 1
0
 /**
  * @param Config $config
  * @return Route
  */
 public static function element($config)
 {
     $spec = $config->core();
     $type = $config->value('type');
     //
     if ($type) {
         $class = str_replace('~', __NAMESPACE__, $type);
         $factory = "{$class}::factory";
         if (is_callable($factory)) {
             $route = $factory($config);
         } else {
             throw new Exception\RuntimeException("Factory [{$factory}] is not callable", 1);
         }
         if (!$route instanceof Route) {
             throw new Exception\RuntimeException("Factory [{$factory}] did not resurn a Route instance", 2);
         }
     } elseif (isset($spec['regex'])) {
         $route = RegexRoute::factory($config);
     } elseif (isset($spec['path']) || isset($spec['domain'])) {
         $route = SimpleRoute::factory($config);
     } else {
         $route = SegmentRoute::factory($config);
     }
     return $route;
 }
Ejemplo n.º 2
0
 public function testAssemble1()
 {
     $route = new R\SimpleRoute("/admin");
     $uri = $route->assemble(R\Destination::match([]), '/test');
     $this->assertEquals("/test/admin", $uri->toString());
 }