Skip to content
Draft
2 changes: 1 addition & 1 deletion src/SPC/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* static-php-cli console app entry
*/
final class ConsoleApplication extends Application
class ConsoleApplication extends Application
{
public const VERSION = '2.5.1';

Expand Down
14 changes: 14 additions & 0 deletions src/SPC/builder/BuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class BuilderProvider
{
private static ?BuilderBase $builder = null;

private static ?\Closure $customizeBuilder = null;

/**
* @param \Closure(BuilderBase): void $callback
*/
public static function customize(\Closure $callback): void
{
self::$customizeBuilder = $callback;
}

/**
* @throws FileSystemException
* @throws RuntimeException
Expand All @@ -36,6 +46,10 @@ public static function makeBuilderByInput(InputInterface $input): BuilderBase
'BSD' => new BSDBuilder($input->getOptions()),
default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'),
};
// allow to add/customize builder instance early
if (self::$customizeBuilder) {
call_user_func_array(self::$customizeBuilder, [&self::$builder]);
}
return self::$builder;
}

Expand Down
4 changes: 4 additions & 0 deletions src/SPC/builder/unix/UnixBuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function proveLibs(array $sorted_libraries): void
ROOT_DIR . '/src/SPC/builder/' . osfamily2dir() . '/library',
'SPC\builder\\' . osfamily2dir() . '\library'
);
$classes = array_merge($classes, FileSystem::getClassesPsr4(
WORKING_DIR . '/src/builder/' . osfamily2dir() . '/library',
'App\builder\\' . osfamily2dir() . '\library'
));
foreach ($classes as $class) {
if (defined($class . '::NAME') && $class::NAME !== 'unknown' && Config::getLib($class::NAME) !== null) {
$support_lib_list[$class::NAME] = $class;
Expand Down
28 changes: 16 additions & 12 deletions src/SPC/builder/windows/WindowsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
cmd()->cd(SOURCE_PATH . '\php-src')
->exec(
"{$this->sdk_prefix} configure.bat --task-args \"" .
'--disable-all ' .
'--disable-cgi ' .
'--with-php-build=' . BUILD_ROOT_PATH . ' ' .
'--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' .
'--with-extra-libs=' . BUILD_LIB_PATH . ' ' .
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
$config_file_scan_dir .
"{$this->makeExtensionArgs()} " .
$zts .
'"'
'--disable-all ' .
'--disable-cgi ' .
'--with-php-build=' . BUILD_ROOT_PATH . ' ' .
'--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' .
'--with-extra-libs=' . BUILD_LIB_PATH . ' ' .
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
($enableMicro ? ('--enable-micro=yes ' . $micro_logo . $micro_w32) : '--enable-micro=no ') .
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
$config_file_scan_dir .
"{$this->makeExtensionArgs()} " .
$zts .
'"'
);

SourcePatcher::patchBeforeMake($this);
Expand Down Expand Up @@ -223,6 +223,10 @@ public function proveLibs(array $sorted_libraries): void
ROOT_DIR . '\src\SPC\builder\\' . osfamily2dir() . '\library',
'SPC\builder\\' . osfamily2dir() . '\library'
);
$classes = array_merge($classes, FileSystem::getClassesPsr4(
WORKING_DIR . '\src\builder\\' . osfamily2dir() . '\library',
'App\builder\\' . osfamily2dir() . '\library'
));
foreach ($classes as $class) {
if (defined($class . '::NAME') && $class::NAME !== 'unknown' && Config::getLib($class::NAME) !== null) {
$support_lib_list[$class::NAME] = $class;
Expand Down
13 changes: 11 additions & 2 deletions src/SPC/store/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@ public static function loadConfigArray(string $config, ?string $config_dir = nul
WORKING_DIR . '/config/' . $config . '.json',
ROOT_DIR . '/config/' . $config . '.json',
];

$all = [];
foreach ($tries as $try) {
if (file_exists($try)) {
$json = json_decode(self::readFile($try), true);
if (!is_array($json)) {
throw new FileSystemException('Reading ' . $try . ' failed');
}
return $json;
$all = array_merge($json, $all);
}
}
throw new FileSystemException('Reading ' . $config . '.json failed');

ksort($all);

if (count($all) === 0) {
throw new FileSystemException('Reading ' . $config . '.json failed');
}

return $all;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/SPC/util/CustomExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(protected string $ext_name) {}
public static function loadCustomExt(): void
{
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/builder/extension', 'SPC\builder\extension');
$classes = array_merge($classes, FileSystem::getClassesPsr4(WORKING_DIR . '/src/builder/extension', 'App\builder\extension'));
foreach ($classes as $class) {
$reflection = new \ReflectionClass($class);
foreach ($reflection->getAttributes(CustomExt::class) as $attribute) {
Expand Down
Loading