]> BookStack Code Mirror - system-cli/blob - src/Services/RequirementsValidator.php
Made changes based upon freebsd/openbsd 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     protected static string $phpVersion = '8.0.2';
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     ];
25
26     /**
27      * Ensure the required PHP extensions are installed for this command.
28      * @throws Exception
29      */
30     public static function validate(): void
31     {
32         $errors = [];
33
34         if (version_compare(PHP_VERSION, static::$phpVersion) < 0) {
35             $errors[] = sprintf("PHP >= %s is required to install BookStack.", static::$phpVersion);
36         }
37
38         foreach (static::$extensions as $extension) {
39             if (!extension_loaded($extension)) {
40                 $errors[] = "The \"{$extension}\" PHP extension is required but not active.";
41             }
42         }
43
44         try {
45             (new ProgramRunner('git', '/usr/bin/git'))->ensureFound();
46             (new ProgramRunner('php', '/usr/bin/php'))->ensureFound();
47         } catch (Exception $exception) {
48             $errors[] = $exception->getMessage();
49         }
50
51         if (count($errors) > 0) {
52             throw new Exception("Requirements failed with following errors:\n" . implode("\n", $errors));
53         }
54     }
55 }