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