public static function readAndCache($configFile, $isCli = null, $pseudoScriptName = '') { if ($isCli === null) { $isCli = jServer::isCLI(); } $config = self::read($configFile, false, $isCli, $pseudoScriptName); $tempPath = jApp::tempPath(); jFile::createDir($tempPath); if (BYTECODE_CACHE_EXISTS) { $filename = $tempPath . str_replace('/', '~', $configFile) . '.conf.php'; if ($f = @fopen($filename, 'wb')) { fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>"); fclose($f); } else { throw new Exception('Error while writing configuration cache file -- ' . $filename); } } else { jIniFile::write(get_object_vars($config), $tempPath . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n"); } return $config; }
/** * read the given ini file. Merge it with the content of defaultconfig.ini.php * It also calculates some options. It stores the result in a temporary file * @param string $configFile the config file name * @return object an object which contains configuration values */ public static function read($configFile) { if (JELIX_APP_TEMP_PATH == '/') { // 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. die('Jelix Error: Application temp directory doesn\'t exist !'); } if (!is_writable(JELIX_APP_TEMP_PATH)) { die('Jelix Error: Application temp directory is not writable'); } $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php'); if ($commonConfig = parse_ini_file(JELIX_APP_CONFIG_PATH . 'defaultconfig.ini.php', true)) { self::_mergeConfig($config, $commonConfig); } if ($configFile != 'defaultconfig.ini.php') { if (!file_exists(JELIX_APP_CONFIG_PATH . $configFile)) { die("Jelix config file {$configFile} is missing !"); } if (false === ($userConfig = parse_ini_file(JELIX_APP_CONFIG_PATH . $configFile, true))) { die("Syntax error in the Jelix config file {$configFile} !"); } self::_mergeConfig($config, $userConfig); } $config = (object) $config; self::prepareConfig($config); if (BYTECODE_CACHE_EXISTS) { $filename = JELIX_APP_TEMP_PATH . str_replace('/', '~', $configFile) . '.conf.php'; if ($f = @fopen($filename, 'wb')) { fwrite($f, '<?php $config = ' . var_export(get_object_vars($config), true) . ";\n?>"); fclose($f); } else { throw new Exception('(24)Error while writing config cache file ' . $filename); } } else { jIniFile::write(get_object_vars($config), JELIX_APP_TEMP_PATH . str_replace('/', '~', $configFile) . '.resultini.php', ";<?php die('');?>\n"); } return $config; }