From 4ba92b08cac34839681c713fa05740f952556372 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Tue, 21 May 2024 14:56:54 +0800 Subject: [PATCH] Add extension version and env check method (#458) --- src/SPC/ConsoleApplication.php | 9 ++------- src/SPC/builder/extension/opcache.php | 2 +- src/SPC/builder/extension/protobuf.php | 19 +++++++++++++++++++ src/SPC/builder/extension/swow.php | 7 +++++++ 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/SPC/builder/extension/protobuf.php diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index 22a89ed1..c18856f5 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -16,9 +16,8 @@ use SPC\command\ExtractCommand; use SPC\command\InstallPkgCommand; use SPC\command\MicroCombineCommand; +use SPC\command\SwitchPhpVersionCommand; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Command\HelpCommand; -use Symfony\Component\Console\Command\ListCommand; /** * static-php-cli console app entry @@ -43,6 +42,7 @@ public function __construct() new DumpLicenseCommand(), new ExtractCommand(), new MicroCombineCommand(), + new SwitchPhpVersionCommand(), // Dev commands new AllExtCommand(), @@ -51,9 +51,4 @@ public function __construct() ] ); } - - protected function getDefaultCommands(): array - { - return [new HelpCommand(), new ListCommand()]; - } } diff --git a/src/SPC/builder/extension/opcache.php b/src/SPC/builder/extension/opcache.php index 0bd972d6..a0af4a8f 100644 --- a/src/SPC/builder/extension/opcache.php +++ b/src/SPC/builder/extension/opcache.php @@ -18,7 +18,7 @@ class opcache extends Extension */ public function validate(): void { - if ($this->builder->getPHPVersionID() < 80000) { + if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') { throw new WrongUsageException('Statically compiled PHP with Zend Opcache only available for PHP >= 8.0 !'); } } diff --git a/src/SPC/builder/extension/protobuf.php b/src/SPC/builder/extension/protobuf.php new file mode 100644 index 00000000..9bab1a32 --- /dev/null +++ b/src/SPC/builder/extension/protobuf.php @@ -0,0 +1,19 @@ +builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') { + throw new \RuntimeException('The latest protobuf extension requires PHP 8.0 or later'); + } + } +} diff --git a/src/SPC/builder/extension/swow.php b/src/SPC/builder/extension/swow.php index a43fdc1d..3b2f91d9 100644 --- a/src/SPC/builder/extension/swow.php +++ b/src/SPC/builder/extension/swow.php @@ -11,6 +11,13 @@ #[CustomExt('swow')] class swow extends Extension { + public function validate(): void + { + if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') { + throw new RuntimeException('The latest swow extension requires PHP 8.0 or later'); + } + } + public function getUnixConfigureArg(): string { $arg = '--enable-swow';