mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 09:25:35 +08:00
Separate package config
This commit is contained in:
@@ -13,6 +13,8 @@ use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Registry
|
||||
{
|
||||
private static ?string $current_registry_name = null;
|
||||
|
||||
/** @var string[] List of loaded registries */
|
||||
private static array $loaded_registries = [];
|
||||
|
||||
@@ -35,7 +37,7 @@ class Registry
|
||||
public static function getRegistryConfig(?string $registry_name = null): array
|
||||
{
|
||||
if ($registry_name === null && spc_mode(SPC_MODE_SOURCE)) {
|
||||
return self::$registry_configs['internal'];
|
||||
return self::$registry_configs['core'];
|
||||
}
|
||||
if ($registry_name !== null && isset(self::$registry_configs[$registry_name])) {
|
||||
return self::$registry_configs[$registry_name];
|
||||
@@ -83,6 +85,8 @@ class Registry
|
||||
|
||||
logger()->debug("Loading registry '{$registry_name}' from file: {$registry_file}");
|
||||
|
||||
self::$current_registry_name = $registry_name;
|
||||
|
||||
// Load composer autoload if specified (for external registries with their own dependencies)
|
||||
if (isset($data['autoload']) && is_string($data['autoload'])) {
|
||||
$autoload_path = FileSystem::fullpath($data['autoload'], dirname($registry_file));
|
||||
@@ -94,24 +98,6 @@ class Registry
|
||||
}
|
||||
}
|
||||
|
||||
// load doctor items from PSR-4 directories
|
||||
if (isset($data['doctor']['psr-4']) && is_assoc_array($data['doctor']['psr-4'])) {
|
||||
foreach ($data['doctor']['psr-4'] as $namespace => $path) {
|
||||
$path = FileSystem::fullpath($path, dirname($registry_file));
|
||||
DoctorLoader::loadFromPsr4Dir($path, $namespace, $auto_require);
|
||||
}
|
||||
}
|
||||
|
||||
// load doctor items from specific classes
|
||||
// Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"}
|
||||
if (isset($data['doctor']['classes']) && is_array($data['doctor']['classes'])) {
|
||||
foreach ($data['doctor']['classes'] as $key => $value) {
|
||||
[$class, $file] = self::parseClassEntry($key, $value);
|
||||
self::requireClassFile($class, $file, dirname($registry_file), $auto_require);
|
||||
DoctorLoader::loadFromClass($class);
|
||||
}
|
||||
}
|
||||
|
||||
// load package configs
|
||||
if (isset($data['package']['config']) && is_array($data['package']['config'])) {
|
||||
foreach ($data['package']['config'] as $path) {
|
||||
@@ -136,6 +122,24 @@ class Registry
|
||||
}
|
||||
}
|
||||
|
||||
// load doctor items from PSR-4 directories
|
||||
if (isset($data['doctor']['psr-4']) && is_assoc_array($data['doctor']['psr-4'])) {
|
||||
foreach ($data['doctor']['psr-4'] as $namespace => $path) {
|
||||
$path = FileSystem::fullpath($path, dirname($registry_file));
|
||||
DoctorLoader::loadFromPsr4Dir($path, $namespace, $auto_require);
|
||||
}
|
||||
}
|
||||
|
||||
// load doctor items from specific classes
|
||||
// Supports both array format ["ClassName"] and map format {"ClassName": "path/to/file.php"}
|
||||
if (isset($data['doctor']['classes']) && is_array($data['doctor']['classes'])) {
|
||||
foreach ($data['doctor']['classes'] as $key => $value) {
|
||||
[$class, $file] = self::parseClassEntry($key, $value);
|
||||
self::requireClassFile($class, $file, dirname($registry_file), $auto_require);
|
||||
DoctorLoader::loadFromClass($class);
|
||||
}
|
||||
}
|
||||
|
||||
// load packages from PSR-4 directories
|
||||
if (isset($data['package']['psr-4']) && is_assoc_array($data['package']['psr-4'])) {
|
||||
foreach ($data['package']['psr-4'] as $namespace => $path) {
|
||||
@@ -193,6 +197,7 @@ class Registry
|
||||
}
|
||||
ConsoleApplication::_addAdditionalCommands($instances);
|
||||
}
|
||||
self::$current_registry_name = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,6 +305,11 @@ class Registry
|
||||
return self::$loaded_artifact_configs;
|
||||
}
|
||||
|
||||
public static function getCurrentRegistryName(): ?string
|
||||
{
|
||||
return self::$current_registry_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a class entry from the classes array.
|
||||
* Supports two formats:
|
||||
|
||||
Reference in New Issue
Block a user