From d8d9f389ba1a75df812b7a1b31d140df0aa043ea Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 6 Feb 2026 16:33:13 +0800 Subject: [PATCH] Refactor patching logic for Alpine Linux and macOS in attr.php --- src/Package/Artifact/attr.php | 6 +++--- src/globals/functions.php | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Package/Artifact/attr.php b/src/Package/Artifact/attr.php index e80c8c83..9974a4a2 100644 --- a/src/Package/Artifact/attr.php +++ b/src/Package/Artifact/attr.php @@ -7,6 +7,7 @@ namespace Package\Artifact; use StaticPHP\Artifact\Artifact; use StaticPHP\Attribute\Artifact\AfterSourceExtract; use StaticPHP\Attribute\PatchDescription; +use StaticPHP\Runtime\SystemTarget; use StaticPHP\Util\SourcePatcher; use StaticPHP\Util\System\LinuxUtil; @@ -16,8 +17,7 @@ class attr #[PatchDescription('Patch attr for Alpine Linux (musl) and macOS - gethostname declaration')] public function patchAttrForAlpine(Artifact $artifact): void { - if (PHP_OS_FAMILY === 'Darwin' || PHP_OS_FAMILY === 'Linux' && LinuxUtil::isMuslDist()) { - SourcePatcher::patchFile('attr_alpine_gethostname.patch', $artifact->getSourceDir()); - } + spc_skip_unless(SystemTarget::getTargetOS() === 'Darwin' || SystemTarget::getTargetOS() === 'Linux' && !LinuxUtil::isMuslDist(), 'Only for Alpine Linux (musl) and macOS'); + SourcePatcher::patchFile('attr_alpine_gethostname.patch', $artifact->getSourceDir()); } } diff --git a/src/globals/functions.php b/src/globals/functions.php index e04bad5e..712cf621 100644 --- a/src/globals/functions.php +++ b/src/globals/functions.php @@ -320,17 +320,6 @@ function get_display_path(string $path): string throw new WrongUsageException("Cannot convert path: {$path}"); } -/** - * Get the global DI container instance. - * - * @deprecated Use ApplicationContext::getContainer() or dependency injection instead. - * This function is kept for backward compatibility during the migration period. - */ -function spc_container(): DI\Container -{ - return \StaticPHP\DI\ApplicationContext::getContainer(); -} - /** * Skip the current operation if the condition is true. * You should ALWAYS use this function inside an attribute callback. @@ -345,6 +334,18 @@ function spc_skip_if(bool $condition, string $message = ''): void } } +/** + * Skip the current operation unless the condition is true. + * You should ALWAYS use this function inside an attribute callback. + * + * @param bool $condition Condition to evaluate + * @param string $message Optional message for the skip exception + */ +function spc_skip_unless(bool $condition, string $message = ''): void +{ + spc_skip_if(!$condition, $message); +} + /** * Parse extension list from string, replace alias and filter internal extensions. *