mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-20 23:35:37 +08:00
Fix config yaml support
This commit is contained in:
@@ -7,6 +7,7 @@ namespace StaticPHP\Config;
|
|||||||
use StaticPHP\Exception\WrongUsageException;
|
use StaticPHP\Exception\WrongUsageException;
|
||||||
use StaticPHP\Registry\Registry;
|
use StaticPHP\Registry\Registry;
|
||||||
use StaticPHP\Runtime\SystemTarget;
|
use StaticPHP\Runtime\SystemTarget;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
class PackageConfig
|
class PackageConfig
|
||||||
{
|
{
|
||||||
@@ -47,10 +48,12 @@ class PackageConfig
|
|||||||
if ($content === false) {
|
if ($content === false) {
|
||||||
throw new WrongUsageException("Failed to read package config file: {$file}");
|
throw new WrongUsageException("Failed to read package config file: {$file}");
|
||||||
}
|
}
|
||||||
$data = json_decode($content, true);
|
// judge extension
|
||||||
if (!is_array($data)) {
|
$data = match (pathinfo($file, PATHINFO_EXTENSION)) {
|
||||||
throw new WrongUsageException("Invalid JSON format in package config file: {$file}");
|
'json' => json_decode($content, true),
|
||||||
}
|
'yml', 'yaml' => Yaml::parse($content),
|
||||||
|
default => throw new WrongUsageException("Unsupported package config file format: {$file}"),
|
||||||
|
};
|
||||||
ConfigValidator::validateAndLintPackages(basename($file), $data);
|
ConfigValidator::validateAndLintPackages(basename($file), $data);
|
||||||
foreach ($data as $pkg_name => $config) {
|
foreach ($data as $pkg_name => $config) {
|
||||||
self::$package_configs[$pkg_name] = $config;
|
self::$package_configs[$pkg_name] = $config;
|
||||||
|
|||||||
Reference in New Issue
Block a user