public function testSimple1() { $request = new Request(); $root = "/demo"; $request->setRoot($root); $request->getUri()->setPath("{$root}/admin/view/42"); $context = new R\Destination(); // $context->setRemainder("/admin/article/view/123/the-slug"); $route = new R\RegexRoute("|^/admin/(?<action>[\\w]+)|", "{~}/admin/{action}"); $dest = $route->route($request, $context); // var_dump($dest); $uri = $route->assemble(R\Destination::match(['action' => "index"]), $root); // var_dump($uri); }
/** * @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; }
/** * @param Destination $destination * @param array $params */ protected function processParams(Destination $destination, array $params) { $target = parent::processParams($destination, $params); foreach ($params as $name => $value) { if (!$this->testParam($name, $value)) { $destination->setMatch(false); break; } } return $target; }