diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index c0b66223..6ba6d9a8 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -227,12 +227,22 @@ abstract class BuilderBase /** * Get PHP Version ID from php-src/main/php_version.h + * + * @throws RuntimeException + * @throws WrongUsageException */ public function getPHPVersionID(): int { + if (!file_exists(SOURCE_PATH . '/php-src/main/php_version.h')) { + throw new WrongUsageException('PHP source files are not available, you need to download them first'); + } + $file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h'); - preg_match('/PHP_VERSION_ID (\d+)/', $file, $match); - return intval($match[1]); + if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0) { + return intval($match[1]); + } + + throw new RuntimeException('PHP version file format is malformed, please remove it and download again'); } /** diff --git a/src/SPC/builder/extension/openssl.php b/src/SPC/builder/extension/openssl.php index 447011da..a81f24b5 100644 --- a/src/SPC/builder/extension/openssl.php +++ b/src/SPC/builder/extension/openssl.php @@ -6,7 +6,6 @@ namespace SPC\builder\extension; use SPC\builder\Extension; use SPC\util\CustomExt; -use SPC\util\Util; #[CustomExt('openssl')] class openssl extends Extension @@ -14,12 +13,13 @@ class openssl extends Extension public function patchBeforeMake(): bool { // patch openssl3 with php8.0 bug - if (file_exists(SOURCE_PATH . '/openssl/VERSION.dat') && Util::getPHPVersionID() < 80100) { + if (file_exists(SOURCE_PATH . '/openssl/VERSION.dat') && $this->builder->getPHPVersionID() < 80100) { $openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c'); $openssl_c = preg_replace('/REGISTER_LONG_CONSTANT\s*\(\s*"OPENSSL_SSLV23_PADDING"\s*.+;/', '', $openssl_c); file_put_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c', $openssl_c); return true; } + return false; } } diff --git a/src/SPC/builder/extension/swow.php b/src/SPC/builder/extension/swow.php index fdea5a6e..a43fdc1d 100644 --- a/src/SPC/builder/extension/swow.php +++ b/src/SPC/builder/extension/swow.php @@ -7,7 +7,6 @@ namespace SPC\builder\extension; use SPC\builder\Extension; use SPC\exception\RuntimeException; use SPC\util\CustomExt; -use SPC\util\Util; #[CustomExt('swow')] class swow extends Extension @@ -25,7 +24,7 @@ class swow extends Extension */ public function patchBeforeBuildconf(): bool { - if (Util::getPHPVersionID() >= 80000 && !is_link(SOURCE_PATH . '/php-src/ext/swow')) { + if ($this->builder->getPHPVersionID() >= 80000 && !is_link(SOURCE_PATH . '/php-src/ext/swow')) { if (PHP_OS_FAMILY === 'Windows') { f_passthru('cd ' . SOURCE_PATH . '/php-src/ext && mklink /D swow swow-src\ext'); } else { diff --git a/src/SPC/util/Util.php b/src/SPC/util/Util.php deleted file mode 100644 index ff017527..00000000 --- a/src/SPC/util/Util.php +++ /dev/null @@ -1,18 +0,0 @@ -