Пример #1
0
 public static function getValueByKey($key, $valueType = _STRING)
 {
     $config = "";
     try {
         if (empty($key)) {
             throw new Exception("参数异常!");
             Tool::logger(__METHOD__, __LINE__, "参数异常!");
         }
         if (empty(self::$configs)) {
             self::$configs = Tool::readConfig();
         }
         if (isset(self::$configs[$key])) {
             $config = self::$configs[$key];
             if ($valueType === _BOOL) {
                 //bool类型
                 $config = $config == TRUE;
             } else {
                 if ($valueType === _INT) {
                     //int类型
                     if (is_numeric($config)) {
                         $config = intval($config);
                     } else {
                         $config = -1;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         Tool::logger(__METHOD__, __LINE__, sprintf("读取配置文件失败: %s", $e->getMessage()));
     }
     return $config;
 }
Пример #2
0
 /**
  * @param string|null $configPath
  */
 protected function __construct($configPath = null)
 {
     if ($configPath) {
         $this->configPath = $configPath;
     }
     try {
         if ((self::$configs = parse_ini_file($this->configPath)) === false) {
             throw new \Exception('Unable to open config file');
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Пример #3
0
 /**
  * Parse application config files
  */
 public static function parseApplicationFiles()
 {
     foreach (new GlobIterator('app/config/*.ini', GlobIterator::CURRENT_AS_PATHNAME) as $file) {
         self::$configs = array_merge(self::$configs, parse_ini_file($file));
     }
 }
 public static function load()
 {
     self::$configs = parse_ini_file('config/config.ini.php');
 }