]> BookStack Code Mirror - system-cli/blob - src/Services/RequirementsValidator.php
Bumped version
[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     protected static string $phpVersion = '8.2.0';
10     protected static array $extensions = [
11         'curl',
12         'dom',
13         'fileinfo',
14         'gd',
15         'iconv',
16         'libxml',
17         'mbstring',
18         'mysqlnd',
19         'pdo_mysql',
20         'session',
21         'simplexml',
22         'tokenizer',
23         'xml',
24         'zip',
25     ];
26
27     /**
28      * Ensure the required PHP extensions are installed for this command.
29      * @throws Exception
30      */
31     public static function validate(): void
32     {
33         $errors = [];
34
35         if (version_compare(PHP_VERSION, static::$phpVersion) < 0) {
36             $errors[] = sprintf("PHP >= %s is required to install BookStack.", static::$phpVersion);
37         }
38
39         foreach (static::$extensions as $extension) {
40             if (!extension_loaded($extension)) {
41                 $errors[] = "The \"{$extension}\" PHP extension is required but not active.";
42             }
43         }
44
45         try {
46             (new ProgramRunner('git', '/usr/bin/git'))->ensureFound();
47             (new ProgramRunner('php', '/usr/bin/php'))->ensureFound();
48         } catch (Exception $exception) {
49             $errors[] = $exception->getMessage();
50         }
51
52         if (count($errors) > 0) {
53             throw new Exception("Requirements failed with following errors:\n" . implode("\n", $errors));
54         }
55     }
56 }