mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
add yaml and toml config support
This commit is contained in:
@@ -274,10 +274,26 @@ class RefactoredConfig
|
|||||||
break;
|
break;
|
||||||
case 'yaml':
|
case 'yaml':
|
||||||
case 'yml':
|
case 'yml':
|
||||||
// TODO: 实现yaml解析
|
$yaml_parser_class = 'Symfony\Component\Yaml\Yaml';
|
||||||
|
if (!class_exists($yaml_parser_class)) {
|
||||||
|
throw ConfigException::loadConfigFailed($path, 'YAML 解析器未安装');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$config = $yaml_parser_class::parse($content);
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
throw ConfigException::loadConfigFailed($path, $e->getMessage());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'toml':
|
case 'toml':
|
||||||
// TODO: 实现toml解析
|
$toml_parser_class = 'Yosymfony\Toml\Toml';
|
||||||
|
if (!class_exists($toml_parser_class)) {
|
||||||
|
throw ConfigException::loadConfigFailed($path, 'TOML 解析器未安装');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$config = $toml_parser_class::parse($content);
|
||||||
|
} catch (\RuntimeException $e) {
|
||||||
|
throw ConfigException::loadConfigFailed($path, $e->getMessage());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw ConfigException::unsupportedFileType($path);
|
throw ConfigException::unsupportedFileType($path);
|
||||||
|
|||||||
Reference in New Issue
Block a user