コード例 #1
0
ファイル: AbstractConfig.php プロジェクト: gmo/common
 protected static function doSetConfig()
 {
     $file = Path::truePath(static::setConfigFile(), static::getProjectDir());
     if (!file_exists($file)) {
         throw new ConfigException("Config file doesn't exist");
     }
     $type = pathinfo($file, PATHINFO_EXTENSION);
     if ($type === "ini") {
         static::$config = parse_ini_file($file, true);
         static::$configFileType = "ini";
     } elseif ($type === "json") {
         static::$config = json_decode(file_get_contents($file), true);
         static::$configFileType = "json";
     } elseif ($type === 'yml') {
         static::$config = Yaml::parse(file_get_contents($file));
         static::$configFileType = "yaml";
     } else {
         throw new ConfigException("Unknown config file format");
     }
     if (!static::$config) {
         throw new ConfigException("Unable to parse {$type} file: {$file}");
     }
     static::$config = ArrayCollection::createRecursive(static::$config);
 }