mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 05:14:52 +08:00
* Add phpmicro win32 mode support * Bump version to 2.2.4 * Add micro win32 build tests for actions * cs-fix and update deps
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace SPC\util;
|
|
|
|
use SPC\builder\Extension;
|
|
use SPC\exception\FileSystemException;
|
|
use SPC\store\FileSystem;
|
|
|
|
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS)]
|
|
class CustomExt
|
|
{
|
|
private static array $custom_ext_class = [];
|
|
|
|
public function __construct(protected string $ext_name) {}
|
|
|
|
/**
|
|
* Load all custom extension classes
|
|
*
|
|
* @throws \ReflectionException
|
|
* @throws FileSystemException
|
|
*/
|
|
public static function loadCustomExt(): void
|
|
{
|
|
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/builder/extension', 'SPC\builder\extension');
|
|
foreach ($classes as $class) {
|
|
$reflection = new \ReflectionClass($class);
|
|
foreach ($reflection->getAttributes(CustomExt::class) as $attribute) {
|
|
self::$custom_ext_class[$attribute->getArguments()[0]] = $class;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function getExtClass(string $ext_name): string
|
|
{
|
|
return self::$custom_ext_class[$ext_name] ?? Extension::class;
|
|
}
|
|
}
|