<?php class Util_Common_Core { const WHICHFILE = 'release'; // local, test, release /** * 获取配置文件所在目录 * * @return string */ private static function getConfigPath() { return defined('SITE_CONFIG_PATH') ? SITE_CONFIG_PATH : ''; } /** * 返回分词配置文件位置 * * @return string */ public static function loadDw() { return self::getConfigPath() . '/dw.' . self::_checkip() . 'config.php'; } /** * 返回邮件服务器配置文件位置 * * @return string */ public static function loadMail() { return self::getConfigPath() . '/mail.' . self::_checkip() . 'config.php'; } /** * 返回分搜索引擎配置文件 * * @return string */ public static function loadSe() { return self::getConfigPath() . '/search.' . self::_checkip() . 'config.php'; } /** * 返回缓存配置文件位置 * * @return string */ public static function loadCacheMem() { return self::getConfigPath() . '/cache.' . self::_checkip() . 'config.php'; } /** * 返回数据库配置文件位置 * * @return string */ public static function loadDbMysql() { $dbConfig = array('local'=> 'local.', 'test'=> 'test.','release'=> 'rls.','releasebg'=> 'rlsbg.'); $dbEnv = strtolower(defined('RELEASE_DB_ENV') ? RELEASE_DB_ENV :''); $checkip = isset($dbConfig[$dbEnv]) ? $dbConfig[$dbEnv] : self::_checkip(); return self::getConfigPath() . '/db.' . $checkip . 'config.php'; } /** * 返回Mogile文件系统配置文件位置 * * @return string */ public static function loadFileMogile() { return self::getConfigPath() . '/file.' . self::_checkip() . 'config.php'; } /** * 返回Ext, Nfs文件系统配置文件位置 * * @return string */ public static function loadFileExt() { return self::getConfigPath() . '/file.' . self::_checkip() . 'config.php'; } /** * 返回Gearman系统配置文件位置 * * @return string */ public static function loadGearman() { return self::getConfigPath() . '/gearman.' . self::_checkip() . 'config.php'; } /** * 返回分词系统配置文件位置 * * @return string */ public static function loadWs() { return self::getConfigPath() . '/ws.' . self::_checkip() . 'config.php'; } /** * 检查当前环境 * * @return string */ private static function _checkip() { $env = defined('RELEASE_ENV') ? RELEASE_ENV : self::WHICHFILE; switch (strtolower($env)) { case 'test': return 'test.'; break; case 'local': return 'local.'; break; case 'release': return 'rls.'; break; default: return ''; } } /** * 获取服务器配置文件 * * @param String $config * @param String $section */ public static function loadConfig($configfn, $section) { $file = new Util_Common_Io_File($configfn); $lastModified = $file->lastModified(); $configFile = "file://" . $configfn; if (Util_Cache_Adapter_Apc::isEnabled()) { $apcFileObj = Util_Cache_Adapter_Apc::get($configFile); if ($apcFileObj['config'] != null && $lastModified == $apcFileObj['lastModified']) { return $apcFileObj['config']; } } $svrobj = new Util_Common_Config_Ini($configfn, $section); if (Util_Cache_Adapter_Apc::isEnabled()) { $val = array( 'config' => $svrobj, 'lastModified' => $lastModified ); Util_Cache_Adapter_Apc::set($configFile, new ArrayObject($val)); } return $svrobj; } }