1 <?php declare(strict_types=1);
3 namespace Cli\Services;
7 class RequirementsValidator
9 protected static string $phpVersion = '8.2.0';
10 protected static array $extensions = [
28 * Ensure the required PHP extensions are installed for this command.
31 public static function validate(): void
35 if (version_compare(PHP_VERSION, static::$phpVersion) < 0) {
36 $errors[] = sprintf("PHP >= %s is required to install BookStack.", static::$phpVersion);
39 foreach (static::$extensions as $extension) {
40 if (!extension_loaded($extension)) {
41 $errors[] = "The \"{$extension}\" PHP extension is required but not active.";
46 (new ProgramRunner('git', '/usr/bin/git'))->ensureFound();
47 (new ProgramRunner('php', '/usr/bin/php'))->ensureFound();
48 } catch (Exception $exception) {
49 $errors[] = $exception->getMessage();
52 if (count($errors) > 0) {
53 throw new Exception("Requirements failed with following errors:\n" . implode("\n", $errors));