Ejemplo n.º 1
0
 /**
  * @param xTend\Objects\Route|string $route
  * @param array $parameters
  * @param array $data
  *
  * @return boolean
  */
 public static function to($route, $parameters = [], $data = [])
 {
     Session::set('xt-data', json_encode($data));
     $handle = '';
     if (is_string($route)) {
         //by route name
         $handle = Router::alias($route)->handle();
     } elseif ($route instanceof Route && is_string($route->handle())) {
         //by route object
         $handle = $route->handle();
     }
     $url = '';
     $parts = explode('/', $handle);
     foreach ($parts as $part) {
         $match = [];
         if (preg_match("/^(rx)(\\{)([a-zA-Z0-9_]+)(\\})(\\{)(.*)(\\})\$/", $part, $match)) {
             if (isset($parameters[$match[3]])) {
                 $url .= '/' . $parameters[$match[3]];
             }
         } elseif (preg_match("/^(\\{)([a-zA-Z0-9_]+)(\\})\$/", $part, $match)) {
             if (isset($parameters[$match[2]])) {
                 $url .= '/' . $parameters[$match[2]];
             }
         } else {
             $url .= "/{$part}";
         }
     }
     header('Location: ' . self::url() . '/' . $url);
     return true;
 }