addArgument( 'php-major-version', InputArgument::REQUIRED, 'PHP major version (supported: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4)', null, fn () => ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] ); $this->no_motd = true; $this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0'); } public function handle(): int { $php_ver = $this->input->getArgument('php-major-version'); if (!in_array($php_ver, ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'])) { // match x.y.z preg_match('/^\d+\.\d+\.\d+$/', $php_ver, $matches); if (!$matches) { $this->output->writeln('Invalid PHP version ' . $php_ver . ' !'); return static::FAILURE; } } if (LockFile::isLockFileExists('php-src')) { $this->output->writeln('Removing old PHP source...'); LockFile::put('php-src', null); } // Download new PHP source $this->output->writeln('Downloading PHP source...'); define('SPC_BUILD_PHP_VERSION', $php_ver); // retry $retry = intval($this->getOption('retry')); f_putenv('SPC_DOWNLOAD_RETRIES=' . $retry); Downloader::downloadSource('php-src', Config::getSource('php-src')); // Remove source/php-src dir FileSystem::removeDir(SOURCE_PATH . '/php-src'); $this->output->writeln('Switched to PHP ' . $php_ver . ' successfully!'); return static::SUCCESS; } }