/** * Load general config and modified by current application config and set it to Vi_Registry * * @return array */ private function loadConfig() { /** * Get BASE_URL, APP_BASE_URL, APP_NAME */ $appName = ''; $baseUrl = dirname($_SERVER['SCRIPT_NAME']); /** * Fix error in Window if we use direct domain like domain.com * and point that domain to this source. It return "\" instead of "/" */ if ('\\' == $baseUrl) { $baseUrl = '/'; } /** * End fix */ $uri = $_SERVER['REQUEST_URI']; $param = substr(rtrim($uri, '/'), strlen(rtrim($baseUrl, '/')) + 1); $arr = explode('/', $param); foreach ($arr as $item) { if ($item == '') { continue; } $appName = $item; break; } // echo '<pre>';print_r($arr);die; // echo $appName;die; // echo '<pre>';print_r($_SERVER);die; /** * Get config from general config */ if (is_file('config.php')) { $generalConfig = (include_once 'config.php'); } else { throw new Exception("Config.php is missing!"); } /** * Load special configuration for Smarty */ $generalConfig['viewConfig']['left_delimiter'] = Vi_Constant::SMARTY_LEFT_DELIMITER; $generalConfig['viewConfig']['right_delimiter'] = Vi_Constant::SMARTY_RIGHT_DELIMITER; /** * Get config from current application */ if ($appName == '') { $appName = $generalConfig['defaultApp']; } /** * Will throw new exception or using default application if application name is not correct. * When using default application. All params (as module/controller/action/param1/value1...) * will recaculate: the incorrect application name will be module name, the old module name will * be action... This solution is useful for default application when users are brownsing without * application name, example: http://yourdomain/controller/action */ $withoutAppName = false; if (!is_dir($this->_root . 'applications/' . $appName)) { if ($generalConfig['forwardToDefaultAppWhenNotFoundAppName']) { /** * Application name will be used to load appliaction's config */ $appName = $generalConfig['defaultApp']; $withoutAppName = true; } else { throw new Exception('Application name is not correct'); } } $appConfigFile = 'applications/' . $appName . '/config.php'; if (is_file($appConfigFile)) { $appConfig = (include_once $appConfigFile); } else { $appConfig = array(); } /** * Read config from general configuration and special application configuration. * The application configuration will have higher priority than general configuration, * and it can be skipped. */ $config = array_merge($generalConfig, $appConfig); /** * In config file, compile and cache dir must have been started with 'tmp/' */ $viewConfig = $config['viewConfig']; // if ('tmp/' !== substr($viewConfig['compile_dir'], 0, 4) || 'tmp/' !== substr($viewConfig['compile_dir'], 0, 4)) { // throw new Exception("In config file, compile and cache dir must have been started with 'tmp/'"); // } $BASE_URL = $baseUrl; if ($baseUrl != "/") { $BASE_URL .= "/"; } Vi_Registry::set('APP_NAME', $appName); Vi_Registry::set('BASE_URL', $BASE_URL); /** * When using default application, the application name can be missed in URL */ if (true == $withoutAppName) { Vi_Registry::set('APP_BASE_URL', $BASE_URL); } else { Vi_Registry::set('APP_BASE_URL', $BASE_URL . $appName . '/'); } Vi_Registry::set('config', $config); Vi_Initializer::$_config = $config; /** * @TODO Read $langCode from COOKIE */ if (null == ($langCode = $config['defaultLangCode'])) { throw new Exception('Missing default language code in config file'); } Vi_Registry::set('langCode', $langCode); return $config; }
*/ //try { // date_default_timezone_set('America/Toronto'); date_default_timezone_set('Asia/Ho_Chi_Minh'); set_include_path('.' . PATH_SEPARATOR . 'libs' . PATH_SEPARATOR . get_include_path()); require_once 'Vi/Constant.php'; require_once 'Zend/Loader.php'; require_once 'Vi/Registry.php'; require_once 'Vi/Db.php'; require_once 'Vi/Layout.php'; require_once 'Vi/Initializer.php'; // Set up autoload. //Zend_Loader::registerAutoload(); /** * TODO TEST LINUX FILE */ umask(0); //ini_set('magic_quotes_gpc', 'Off'); // Change 'currentMode' in config.php to Vi_Constant::PRODUCT_MODE under production environment $initializer = new Vi_Initializer(); $initializer->run(); // Prepare the front controller. $frontController = Vi_Controller_Front::getInstance(); // Dispatch the request using the front controller. $frontController->dispatch(); //} catch (Exception $e) { // /** // * TODO Redirect to error page // */ // include_once 'error.php'; //}