From 0fb8957fc74f327040384ec904e8b851da6b4e14 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 28 Apr 2026 18:50:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8D=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=99=A8=E5=9F=BA=E7=A1=80=E7=B1=BB=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=B3=BB=E7=BB=9F=E7=B1=BB=E5=9E=8B=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CompilerBase 构造函数中添加对父类构造函数的调用 - 为 Translator 类添加 osType 属性和相关平台检测方法 - 根据操作系统类型动态确定 PHP 扩展库文件后缀名 - 实现对 macOS (.dylib) 和 Linux/Windows (.so) 平台的库文件兼容性支持 --- src/Core/Translator.php | 21 +++++++++++++++++++++ src/Php/CompilerBase.php | 1 + src/Php/Translator.php | 5 +++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Core/Translator.php b/src/Core/Translator.php index 0ff39ae1..4fde8327 100644 --- a/src/Core/Translator.php +++ b/src/Core/Translator.php @@ -8,6 +8,27 @@ abstract class Translator protected string $indentStr = "\t"; public string $mode = 'cli'; protected string $lang; + protected string $osType = 'linux'; + + public function __construct() + { + $this->osType = PHP_OS_FAMILY; + } + + public function isMacos(): bool + { + return $this->osType === 'Darwin'; + } + + public function isLinux(): bool + { + return $this->osType === 'Linux'; + } + + public function isWindows(): bool + { + return $this->osType === 'Windows'; + } public function setMode($mode): void { diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index cc501344..40bfe68c 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -268,6 +268,7 @@ class CompilerBase extends \PhpAot\Core\Translator public function __construct(string $rootPath) { + parent::__construct(); if (version_compare(PHP_VERSION, '8.2.0', '<')) { $this->error('PHP 8.2.0 or later is required'); } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index adc62124..791bb4db 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -218,10 +218,11 @@ class Translator extends Preprocessor $this->error('The `php-config` is not found'); } $phpDir = trim($phpDir); - if (!is_file($phpDir . '/lib/libphp.so')) { + $ext = $this->isMacos() ? '.dylib' : '.so'; + if (!is_file($phpDir . '/lib/libphp' . $ext)) { $this->error('The `libphp.so` is not found, please run `make` to build it'); } - if (!is_file($this->getPhpxDir() . '/lib/libphpx.so')) { + if (!is_file($this->getPhpxDir() . '/lib/libphpx' . $ext)) { $this->error('The `libphpx.so` is not found, please run `make` to build it'); }