Add PatchBeforeBuild attribute

This commit is contained in:
crazywhalecc
2026-02-02 16:15:25 +08:00
parent 82ab14165e
commit 3d102363c4
3 changed files with 28 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\Package\Info;
use StaticPHP\Attribute\Package\InitPackage;
use StaticPHP\Attribute\Package\Library;
use StaticPHP\Attribute\Package\PatchBeforeBuild;
use StaticPHP\Attribute\Package\ResolveBuild;
use StaticPHP\Attribute\Package\Stage;
use StaticPHP\Attribute\Package\Target;
@@ -196,6 +197,8 @@ class PackageLoader
match ($method_attribute->getName()) {
// #[BuildFor(PHP_OS_FAMILY)]
BuildFor::class => self::addBuildFunction($pkg, $method_instance, [$instance_class, $method->getName()]),
// #[BeforeBuild]
PatchBeforeBuild::class => self::addPatchBeforeBuildFunction($pkg, [$instance_class, $method->getName()]),
// #[CustomPhpConfigureArg(PHP_OS_FAMILY)]
CustomPhpConfigureArg::class => self::bindCustomPhpConfigureArg($pkg, $method_attribute->newInstance(), [$instance_class, $method->getName()]),
// #[Stage('stage_name')]
@@ -332,6 +335,11 @@ class PackageLoader
$pkg->addBuildFunction($attr->os, $fn);
}
private static function addPatchBeforeBuildFunction(Package $pkg, callable $fn): void
{
$pkg->addPatchBeforeBuildCallback($fn);
}
private static function addStage(\ReflectionMethod $method, Package $pkg, object $instance_class, object $method_instance): void
{
$name = $method_instance->function;