]> BookStack Code Mirror - system-cli/blob - src/Services/RequirementsValidator.php
Made a range of tweaks from testing
[system-cli] / src / Services / RequirementsValidator.php
1 <?php declare(strict_types=1);
2
3 namespace Cli\Services;
4
5 use Exception;
6
7 class RequirementsValidator
8 {
9     /**
10      * Ensure the required PHP extensions are installed for this command.
11      * @throws Exception
12      */
13     public static function validate(): void
14     {
15         $errors = [];
16
17         if (version_compare(PHP_VERSION, '8.0.2') < 0) {
18             $errors[] = "PHP >= 8.0.2 is required to install BookStack.";
19         }
20
21         $requiredExtensions = ['curl', 'gd', 'iconv', 'libxml', 'mbstring', 'mysqlnd', 'xml'];
22         foreach ($requiredExtensions as $extension) {
23             if (!extension_loaded($extension)) {
24                 $errors[] = "The \"{$extension}\" PHP extension is required by not active.";
25             }
26         }
27
28         try {
29             (new ProgramRunner('git', '/usr/bin/git'))->ensureFound();
30             (new ProgramRunner('php', '/usr/bin/php'))->ensureFound();
31         } catch (Exception $exception) {
32             $errors[] = $exception->getMessage();
33         }
34
35         if (count($errors) > 0) {
36             throw new Exception("Requirements failed with following errors:\n" . implode("\n", $errors));
37         }
38     }
39 }