Example #1
0
 /**
  * Init a routing algo
  * @param string  $from      URL source if not provide, Route::go will determine the good route from $_SERVER parameter
  * @return mixed[]
  */
 public static function go($published = true, $lang = 'FR', $host = null)
 {
     $host = !is_string($host) ? $_SERVER['HTTP_HOST'] : $host;
     C::s('FULLURL', 'http://' . $host);
     if (array_key_exists('HTTPS', $_SERVER)) {
         C::s('FULLURL', 'https://' . $host);
     }
     $uri = parse_url($_SERVER['REQUEST_URI']);
     if (substr($uri['path'], -1) == '/') {
         $uri['path'] = substr($uri['path'], 0, -1);
     }
     $route = self::getRoute($host, $uri['path'], $_SERVER['REQUEST_METHOD']);
     if (!is_a($route, 'KLib\\Router')) {
         //PAGE
         $data = \Page::getByUrl($host, $uri['path'], $lang, $published);
         if (!is_a($data, 'Page') && $lang != C::g('DEFAULT_LANG')) {
             $data = \Page::getByUrl($host, $uri['path'], C::g('DEFAULT_LANG'), $published);
         }
         if (!is_a($data, 'Page')) {
             throw new \Exception('PAGE NOT FOUND', 404);
         }
         $route = new Self($data->getBaseUrl(), $uri['path'], $data->getAction(), $data->getMethod(), array_merge($_GET, array('page' => $data)));
     }
     if (!is_a($route, 'KLib\\Router')) {
         throw new \Exception('PAGE NOT FOUND', 404);
     }
     return BaseController::run($route->getController(), $route->getAction(), $route->getArgs());
 }