From d85b9502fc6bf4be15eedc005406aef9c43ad38f Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 23 Dec 2023 00:23:47 +0800 Subject: [PATCH] doctor support windows base --- src/SPC/command/DoctorCommand.php | 5 +++-- src/SPC/doctor/CheckListHandler.php | 19 +++++++++++++++---- src/SPC/doctor/item/OSCheckList.php | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/SPC/command/DoctorCommand.php b/src/SPC/command/DoctorCommand.php index 9aabdeca..bc77511a 100644 --- a/src/SPC/command/DoctorCommand.php +++ b/src/SPC/command/DoctorCommand.php @@ -75,8 +75,9 @@ class DoctorCommand extends BaseCommand } catch (\Throwable $e) { $this->output->writeln('' . $e->getMessage() . ''); - pcntl_signal(SIGINT, SIG_IGN); - + if (extension_loaded('pcntl')) { + pcntl_signal(SIGINT, SIG_IGN); + } return static::FAILURE; } diff --git a/src/SPC/doctor/CheckListHandler.php b/src/SPC/doctor/CheckListHandler.php index bfeb39c4..de5733df 100644 --- a/src/SPC/doctor/CheckListHandler.php +++ b/src/SPC/doctor/CheckListHandler.php @@ -34,12 +34,23 @@ final class CheckListHandler */ public function emitFix(OutputInterface $output, CheckResult $result): void { - pcntl_signal(SIGINT, function () use ($output) { - $output->writeln('You cancelled fix'); - }); + if (PHP_OS_FAMILY === 'Windows') { + sapi_windows_set_ctrl_handler(function () use ($output) { + $output->writeln('You cancelled fix'); + }); + } elseif (extension_loaded('pcntl')) { + pcntl_signal(SIGINT, function () use ($output) { + $output->writeln('You cancelled fix'); + }); + } $fix_result = call_user_func($this->fix_map[$result->getFixItem()], ...$result->getFixParams()); - pcntl_signal(SIGINT, SIG_IGN); + + if (PHP_OS_FAMILY === 'Windows') { + sapi_windows_set_ctrl_handler(null); + } elseif (extension_loaded('pcntl')) { + pcntl_signal(SIGINT, SIG_IGN); + } if ($fix_result) { $output->writeln('Fix done'); diff --git a/src/SPC/doctor/item/OSCheckList.php b/src/SPC/doctor/item/OSCheckList.php index ad6b2551..60ce10c6 100644 --- a/src/SPC/doctor/item/OSCheckList.php +++ b/src/SPC/doctor/item/OSCheckList.php @@ -17,7 +17,7 @@ class OSCheckList public function checkOS(): ?CheckResult { if (!in_array(PHP_OS_FAMILY, ['Darwin', 'Linux', 'BSD'])) { - return CheckResult::fail('Current OS is not supported'); + return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY); } $distro = PHP_OS_FAMILY === 'Linux' ? (' ' . SystemUtil::getOSRelease()['dist']) : ''; return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported');