/** * Inicia a aplicação * @param array $APPConfig * @param string $PublicPath */ static function Initialize(array $APPConfig, $PublicPath = 'public_html') { APP::setGlobal('public_path', $PublicPath); $Action = $Controller = null; self::$APP_CONFIG = $APPConfig; self::$Modules = isset(self::$APP_CONFIG['modules']) ? self::$APP_CONFIG['modules'] : self::$APP_CONFIG; self::$DefaultModule = key(self::$Modules); # URL Variables $values = !empty($_GET['GET_VARS']) ? explode('/', strtolower($_GET['GET_VARS'])) : [self::$DefaultModule, 'index', 'index']; # Modulo if (isset(self::$Modules[$values[0]])) { self::$CurrentModule = $values[0]; unset($values[0]); $values = array_values($values); } else { self::$CurrentModule = self::$DefaultModule; } # Controller if (empty($values[0]) or controller_exists(strtolower($values[0])) === false) { $Controller = 'index'; } else { $Controller = $values[0]; unset($values[0]); $values = array_values($values); } # Action if (empty($values[0]) and controller_action_exists($Controller, 'index')) { $Action = 'indexAction'; } else { if (empty($values[0]) or !($Action = controller_action_exists($Controller, $values[0]))) { self::$Parans['action'] = strtolower(@$values[0]); $Action = 'notFoundPage'; } else { unset($values[0]); $values = array_values($values); } } # Parâmetros númericos self::$Parans = $values; # Parâmetros nomeados if (count(self::$Parans) > 1) { for ($i = 0; $i < count($values); $i += 2) { if (isset($values[$i + 1])) { self::$Parans[$values[$i]] = $values[$i + 1]; } } } # Modulo if (!isset(self::$Parans['module'])) { self::$Parans['module'] = APP::getCurrentModule(); } # Controller if (!isset(self::$Parans['controller'])) { self::$Parans['controller'] = APP::getControllerName(); } # Action if (!isset(self::$Parans['action'])) { self::$Parans['action'] = $Action; } # Valores GET if (preg_match('/\\?/', inputServer('REQUEST_URI'))) { parse_str(preg_replace('/.*\\?/', NULL, inputServer('REQUEST_URI')), $getValues); foreach ($getValues as $key => $value) { $_GET[$key] = $value; if (!isset(self::$Parans[$key])) { self::$Parans[$key] = $value; } } } # Action self::$Action = $Action; # Cria instancia do modulo if (file_exists($ModuleClass = ABSPATH . '/' . self::getCurrentModule(true) . '/Module.class.php')) { file_include($ModuleClass); self::$Module = new Module(); } # Executando a action self::setController($Controller); self::getController()->{$Action}(); }
/** * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. * @return bool * @throws Exception_Exido */ public static function getUri() { // Debug log if (Exido::$log_debug) { Exido::$log->add('EXIDO_DEBUG_LOG', 'Determine current URI'); } Helper::load('input'); // Trying to detect the URI if (inputServer('PATH_INFO')) { self::$current_uri = inputServer('PATH_INFO'); } elseif (inputServer('ORIG_PATH_INFO')) { self::$current_uri = inputServer('ORIG_PATH_INFO'); } elseif (inputServer('REQUEST_URI')) { self::$current_uri = inputServer('REQUEST_URI'); } else { throw new Exception_Exido(__("Can't detect URI")); } // Remove slashes from the start and end of the URI self::$current_uri = trim(self::$current_uri, '/'); if (self::$current_uri !== '') { if ($suffix = Exido::config('global.core.url_suffix') and strpos(self::$current_uri, $suffix) !== false) { // Remove the URL suffix self::$current_uri = preg_replace('#' . preg_quote($suffix) . '$#u', '', self::$current_uri); // Set the URL suffix self::$url_suffix = $suffix; } // Find index file name if ($indexfile = Exido::config('global.core.index_file') and $indexpos = strpos(self::$current_uri, $indexfile) and $indexpos !== false) { // Remove the index file name self::$current_uri = substr(self::$current_uri, 0, $indexpos); } // Reduce multiple slashes into single slashes self::$current_uri = preg_replace('#//+#', '/', self::$current_uri); } return true; }