public function init()
 {
     if (!isset(self::$cache[$this->cache_file]) || empty(self::$cache[$this->cache_file])) {
         if (checkPhpSyntax($this->cache_file)) {
             throw new \Exception($this->cache_file . 'has syntax error, please check the cache file.');
         }
         self::$cache[$this->cache_file] = (include $this->cache_file);
     }
 }
Esempio n. 2
0
 /**
  * 单例模式初始化配置文件
  * @param string $key
  * @throws \Exception
  */
 private static function initConfig($key)
 {
     if (!\defined('CONFIG_PATH')) {
         throw new \Exception('const CONFIG_PATH is not defined');
     }
     if (!\strstr($key, '.')) {
         throw new \Exception('param key does not contain "."');
     }
     $keyInfo = explode('.', $key);
     $configFile = $keyInfo[0];
     if (!isset(self::$config[$configFile])) {
         $realConfigFile = CONFIG_PATH . DIRECTORY_SEPARATOR . $configFile . '.php';
         if (!file_exists($realConfigFile)) {
             throw new \Exception('config file is not exists');
         }
         if (!is_readable($realConfigFile)) {
             throw new \Exception('config file is not readable');
         }
         if (!checkPhpSyntax($realConfigFile)) {
             throw new \Exception('config file contains a syntax error');
         }
         self::$config[$configFile] = (include $realConfigFile);
     }
 }