fix(core): 修复编译器基础类构造函数调用并添加操作系统类型检测支持

- 在 CompilerBase 构造函数中添加对父类构造函数的调用
- 为 Translator 类添加 osType 属性和相关平台检测方法
- 根据操作系统类型动态确定 PHP 扩展库文件后缀名
- 实现对 macOS (.dylib) 和 Linux/Windows (.so) 平台的库文件兼容性支持
pull/1/head
韩天峰 4 months ago
parent 70d06eeb2b
commit 0fb8957fc7
  1. 21
      src/Core/Translator.php
  2. 1
      src/Php/CompilerBase.php
  3. 5
      src/Php/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
{

@ -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');
}

@ -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');
}

Loading…
Cancel
Save