/** * read the given ini file, for the current entry point, or for the entrypoint given * in $pseudoScriptName. Merge it with the content of defaultconfig.ini.php * It also calculates some options. * If you are in a CLI script but you want to load a configuration file for a web entry point * or vice-versa, you need to indicate the $pseudoScriptName parameter with the name of the entry point * @param string $configFile the config file name * @param boolean $allModuleInfo may be true for the installer, which needs all informations * else should be false, these extra informations are * not needed to run the application * @param boolean $isCli indicate if the configuration to read is for a CLI script or no * @param string $pseudoScriptName the name of the entry point, relative to the base path, * corresponding to the readed configuration * @return object an object which contains configuration values */ public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '') { $tempPath = jApp::tempBasePath(); $configPath = jApp::configPath(); if ($tempPath == '/') { // if it equals to '/', this is because realpath has returned false in the application.init.php // so this is because the path doesn't exist. throw new Exception('Application temp directory doesn\'t exist !', 3); } if (!is_writable($tempPath)) { throw new Exception('Application temp base directory is not writable -- (' . $tempPath . ')', 4); } if (!is_writable(jApp::logPath())) { throw new Exception('Application log directory is not writable -- (' . jApp::logPath() . ')', 4); } $config = jelix_read_ini(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); self::$commonConfig = clone $config; @jelix_read_ini($configPath . 'defaultconfig.ini.php', $config); if ($configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Configuration file is missing -- {$configFile}", 5); } if (false === @jelix_read_ini($configPath . $configFile, $config)) { throw new Exception("Syntax error in the configuration file -- {$configFile}", 6); } } self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName); self::$commonConfig = null; return $config; }
/** * load and read the configuration of the application * The combination of all configuration files (the given file * and the mainconfig.ini.php) is stored * in a single temporary file. So it calls the jConfigCompiler * class if needed * @param string $configFile the config file name * @return object it contains all configuration options * @see jConfigCompiler */ public static function load($configFile) { $config = array(); $file = jApp::tempPath() . str_replace('/', '~', $configFile); if (BYTECODE_CACHE_EXISTS) { $file .= '.conf.php'; } else { $file .= '.resultini.php'; } self::$fromCache = true; if (!file_exists($file)) { // no cache, let's compile self::$fromCache = false; } else { $t = filemtime($file); $dc = jApp::mainConfigFile(); $lc = jApp::configPath('localconfig.ini.php'); if (file_exists($dc) && filemtime($dc) > $t || filemtime(jApp::configPath($configFile)) > $t || file_exists($lc) && filemtime($lc) > $t) { // one of the config files have been modified: let's compile self::$fromCache = false; } else { // let's read the cache file if (BYTECODE_CACHE_EXISTS) { include $file; $config = (object) $config; } else { $config = jelix_read_ini($file); } // we check all directories to see if it has been modified if ($config->compilation['checkCacheFiletime']) { foreach ($config->_allBasePath as $path) { if (!file_exists($path) || filemtime($path) > $t) { self::$fromCache = false; break; } } } } } if (!self::$fromCache) { require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php'; return jConfigCompiler::readAndCache($configFile); } else { return $config; } }
/** * read the given ini file, for the current entry point, or for the entrypoint given * in $pseudoScriptName. Merge it with the content of defaultconfig.ini.php * It also calculates some options. * If you are in a CLI script but you want to load a configuration file for a web entry point * or vice-versa, you need to indicate the $pseudoScriptName parameter with the name of the entry point * @param string $configFile the config file name * @param boolean $allModuleInfo may be true for the installer, which needs all informations * else should be false, these extra informations are * not needed to run the application * @param boolean $isCli indicate if the configuration to read is for a CLI script or no * @param string $pseudoScriptName the name of the entry point, relative to the base path, * corresponding to the readed configuration * @return object an object which contains configuration values */ public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '') { $tempPath = jApp::tempBasePath(); $configPath = jApp::configPath(); if ($tempPath == '/') { // if it equals to '/', this is because realpath has returned false in the application.init.php // so this is because the path doesn't exist. throw new Exception('Application temp directory doesn\'t exist !', 3); } if (!is_writable($tempPath)) { throw new Exception('Application temp base directory (' . $tempPath . ') is not writable', 4); } self::$commonConfig = jIniFile::read($configPath . 'defaultconfig.ini.php', true); #if ENABLE_PHP_JELIX $config = jelix_read_ini(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); @jelix_read_ini($configPath . 'defaultconfig.ini.php', $config); if ($configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Config file {$configFile} is missing !", 5); } if (false === @jelix_read_ini($configPath . $configFile, $config)) { throw new Exception("Syntax error in the config file {$configFile} !", 6); } } #else $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); if (self::$commonConfig) { self::_mergeConfig($config, self::$commonConfig); } if ($configFile != 'defaultconfig.ini.php') { if (!file_exists($configPath . $configFile)) { throw new Exception("Config file {$configFile} is missing !", 5); } if (false === ($userConfig = parse_ini_file($configPath . $configFile, true))) { throw new Exception("Syntax error in the config file {$configFile} !", 6); } self::_mergeConfig($config, $userConfig); } $config = (object) $config; #endif self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName); self::$commonConfig = null; return $config; }
/** * load and read the configuration of the application * The combination of all configuration files (the given file * and the defaultconfig.ini.php) is stored * in a single temporary file. So it calls the jConfigCompiler * class if needed * @param string $configFile the config file name * @return object it contains all configuration options * @see jConfigCompiler */ public static function load($configFile) { $config = array(); $file = jApp::tempPath(); #if WITH_BYTECODE_CACHE == 'auto' if (BYTECODE_CACHE_EXISTS) { $file .= str_replace('/', '~', $configFile) . '.conf.php'; } else { $file .= str_replace('/', '~', $configFile) . '.resultini.php'; } #elseif WITH_BYTECODE_CACHE $file .= str_replace('/', '~', $configFile) . '.conf.php'; #else $file .= str_replace('/', '~', $configFile) . '.resultini.php'; #endif $compil = false; if (!file_exists($file)) { // no cache, let's compile $compil = true; } else { $t = filemtime($file); $dc = jApp::configPath('defaultconfig.ini.php'); if (file_exists($dc) && filemtime($dc) > $t || filemtime(jApp::configPath($configFile)) > $t) { // one of the two config file have been modified: let's compile $compil = true; } else { // let's read the cache file #if WITH_BYTECODE_CACHE == 'auto' if (BYTECODE_CACHE_EXISTS) { include $file; $config = (object) $config; } else { #if ENABLE_PHP_JELIX $config = jelix_read_ini($file); #else $config = parse_ini_file($file, true); $config = (object) $config; #endif } #elseif WITH_BYTECODE_CACHE include $file; $config = (object) $config; #else #if ENABLE_PHP_JELIX $config = jelix_read_ini($file); #else $config = parse_ini_file($file, true); $config = (object) $config; #endif #endif // we check all directories to see if it has been modified if ($config->compilation['checkCacheFiletime']) { foreach ($config->_allBasePath as $path) { if (!file_exists($path) || filemtime($path) > $t) { $compil = true; break; } } } } } if ($compil) { require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php'; return jConfigCompiler::readAndCache($configFile); } else { return $config; } }