Exemplo n.º 1
0
 public function testSimple1()
 {
     $request = new Request();
     $root = "/demo";
     $request->setRoot($root);
     $request->getUri()->setPath("{$root}/admin/view/segment");
     $context = new Rt\Destination();
     $route = new Rt\SegmentRoute("/admin[/{action}]");
     $route->setPartial();
     $dest = $route->route($request, $context);
     // var_dump($dest);
     $uri = $route->assemble(Rt\Destination::match(['action' => "index"]), $root);
     // var_dump($uri);
 }
Exemplo n.º 2
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;
 }