Add doctor cache check and version management to ensure environment validation

This commit is contained in:
crazywhalecc
2026-02-28 10:32:50 +08:00
parent 7623b9e673
commit c218aef947
8 changed files with 94 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace StaticPHP\Command;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Doctor\Doctor;
use StaticPHP\Exception\ExceptionHandler;
use StaticPHP\Exception\SPCException;
use Symfony\Component\Console\Command\Command;
@@ -118,6 +119,21 @@ abstract class BaseCommand extends Command
}
}
/**
* Warn the user if doctor has not been run (or is outdated).
* Set SPC_SKIP_DOCTOR_CHECK=1 to suppress.
*/
protected function checkDoctorCache(): void
{
if (getenv('SPC_SKIP_DOCTOR_CHECK') || Doctor::isHealthy()) {
return;
}
$this->output->writeln('');
$this->output->writeln('<comment>[WARNING] Please run `spc doctor` first to verify your build environment.</comment>');
$this->output->writeln('');
sleep(2);
}
protected function getOption(string $name): mixed
{
return $this->input->getOption($name);