mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Throw proper exception when PHP source is not available
This commit is contained in:
parent
8f43a09533
commit
8636f2e7c9
@ -227,12 +227,22 @@ abstract class BuilderBase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get PHP Version ID from php-src/main/php_version.h
|
* Get PHP Version ID from php-src/main/php_version.h
|
||||||
|
*
|
||||||
|
* @throws RuntimeException
|
||||||
|
* @throws WrongUsageException
|
||||||
*/
|
*/
|
||||||
public function getPHPVersionID(): int
|
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');
|
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
|
||||||
preg_match('/PHP_VERSION_ID (\d+)/', $file, $match);
|
if (preg_match('/PHP_VERSION_ID (\d+)/', $file, $match) !== 0) {
|
||||||
return intval($match[1]);
|
return intval($match[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException('PHP version file format is malformed, please remove it and download again');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -6,7 +6,6 @@ namespace SPC\builder\extension;
|
|||||||
|
|
||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
use SPC\util\Util;
|
|
||||||
|
|
||||||
#[CustomExt('openssl')]
|
#[CustomExt('openssl')]
|
||||||
class openssl extends Extension
|
class openssl extends Extension
|
||||||
@ -14,12 +13,13 @@ class openssl extends Extension
|
|||||||
public function patchBeforeMake(): bool
|
public function patchBeforeMake(): bool
|
||||||
{
|
{
|
||||||
// patch openssl3 with php8.0 bug
|
// 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 = 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);
|
$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);
|
file_put_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c', $openssl_c);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,6 @@ namespace SPC\builder\extension;
|
|||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
use SPC\exception\RuntimeException;
|
use SPC\exception\RuntimeException;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
use SPC\util\Util;
|
|
||||||
|
|
||||||
#[CustomExt('swow')]
|
#[CustomExt('swow')]
|
||||||
class swow extends Extension
|
class swow extends Extension
|
||||||
@ -25,7 +24,7 @@ class swow extends Extension
|
|||||||
*/
|
*/
|
||||||
public function patchBeforeBuildconf(): bool
|
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') {
|
if (PHP_OS_FAMILY === 'Windows') {
|
||||||
f_passthru('cd ' . SOURCE_PATH . '/php-src/ext && mklink /D swow swow-src\ext');
|
f_passthru('cd ' . SOURCE_PATH . '/php-src/ext && mklink /D swow swow-src\ext');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace SPC\util;
|
|
||||||
|
|
||||||
class Util
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get current PHP version ID (downloaded)
|
|
||||||
*/
|
|
||||||
public static function getPHPVersionID(): int
|
|
||||||
{
|
|
||||||
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
|
|
||||||
preg_match('/PHP_VERSION_ID (\d+)/', $file, $match);
|
|
||||||
return intval($match[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user