Inheritance: implements Autarky\Routing\RouterInterface
Exemple #1
0
 /**
  * Re-build a Route object from data that has been var_export-ed.
  *
  * @param  array $data
  *
  * @return static
  */
 public static function __set_state($data)
 {
     $route = new static($data['methods'], $data['pattern'], $data['controller'], $data['name'], $data['options']);
     if (static::$router !== null) {
         static::$router->addCachedRoute($route);
     }
     return $route;
 }
Exemple #2
0
 /**
  * Get the URL to a named route.
  *
  * @param  string $name
  * @param  array  $params
  * @param  bool   $relative
  *
  * @return string
  */
 public function getRouteUrl($name, array $params = array(), $relative = false)
 {
     $route = $this->router->getRoute($name);
     $routeParams = [];
     $query = [];
     foreach ($params as $key => $value) {
         if (is_int($key)) {
             $routeParams[] = $value;
         } else {
             $query[$key] = $value;
         }
     }
     $path = $this->routePathGenerator->getRoutePath($route, $routeParams);
     if ($query) {
         $path .= '?' . http_build_query($query);
     }
     if ($relative) {
         $root = $this->requests->getCurrentRequest()->getBaseUrl();
     } else {
         $root = $this->getRootUrl();
     }
     return $root . $path;
 }