From ca3f8a350d1d8e65bcdcc9c9c678179e0904b24e Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 12 Sep 2023 11:29:22 +0200 Subject: [PATCH] Prevent fatal error when php source files are missing --- src/SPC/command/dev/PhpVerCommand.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/SPC/command/dev/PhpVerCommand.php b/src/SPC/command/dev/PhpVerCommand.php index 57374753..05af1267 100644 --- a/src/SPC/command/dev/PhpVerCommand.php +++ b/src/SPC/command/dev/PhpVerCommand.php @@ -9,7 +9,7 @@ use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -#[AsCommand('dev:php-ver', 'Dev command')] +#[AsCommand('dev:php-version', 'Returns version of PHP located source directory', ['dev:php-ver'])] class PhpVerCommand extends BaseCommand { public function initialize(InputInterface $input, OutputInterface $output): void @@ -22,11 +22,19 @@ class PhpVerCommand extends BaseCommand { // Find php from source/php-src $file = SOURCE_PATH . '/php-src/main/php_version.h'; + if (!file_exists($file)) { + $this->output->writeln('PHP source not found, maybe you need to extract first ?'); + + return static::FAILURE; + } + $result = preg_match('/#define PHP_VERSION "([^"]+)"/', file_get_contents($file), $match); if ($result === false) { $this->output->writeln('PHP source not found, maybe you need to extract first ?'); + return static::FAILURE; } + $this->output->writeln('' . $match[1] . ''); return static::SUCCESS; }