/** * Set the route * * @static * @param string request_uri * @param array default_config (lang, route) * @return void */ public static function set_route($request_uri, $default_config = array()) { // set the URI self::$uri = $request_uri; // set default if (empty(self::$default)) { self::$default = $default_config; } // set proptocol if (isset($_SERVER['HTTPS'])) { self::$protocol = 'https'; } // clean uri string $uri_str = ROOT != '/' ? trim(str_replace(ROOT, '', $request_uri), '/') : trim($request_uri, '/'); // set default route if (empty($uri_str)) { $uri_str = $default_config['x3default_route']; } // handle querystring $us = explode('?', $uri_str); // sanitize if (isset($us[1])) { self::$query_string = $us[1]; } // check post self::$post = isset($_POST) && !empty($_POST); // uri segments array self::$args = explode('/', $us[0]); // check alternative languages if (strlen(self::$args[0]) == 2) { self::$lang = array_shift(self::$args); self::set_locale(self::$lang); } // area if (!empty(self::$args)) { if (is_dir(APATH . 'controllers/' . self::$args[0])) { // the area has a dedicated folder if (self::$args[0] == 'x3cli') { // check for valid cli call if (defined('X3CLI') && php_sapi_name() === 'cli') { self::$area = self::$folder = array_shift(self::$args); } } else { self::$area = self::$folder = array_shift(self::$args); } } elseif (isset($default_config[self::$args[0]])) { // the area has not a dedicated folder // set additional area self::$area = array_shift(self::$args); // set the folder self::$folder = $default_config[self::$area]; // add additional area to the areas array self::$areas[self::$area] = $default_config[self::$area . '_id']; } } // controller if (!empty(self::$args)) { self::$control = array_shift(self::$args); } // method if (!empty(self::$args)) { self::$method = array_shift(self::$args); } // home if (empty(self::$control)) { self::$method = self::$control = 'home'; } }