1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\Bundle\CoreInstallerBundle\Util; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Yaml\Yaml; |
17
|
|
|
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel; |
18
|
|
|
|
19
|
|
|
class RequirementChecker |
20
|
|
|
{ |
21
|
|
|
private static $parameters; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* If not installed, or if currentVersion != installedVersion run |
25
|
|
|
* requirement checks. Die on failure. |
26
|
|
|
*/ |
27
|
|
|
public static function verify(): void |
28
|
|
|
{ |
29
|
|
|
// on install or upgrade, check if system requirements are met. |
30
|
|
|
if (version_compare($_ENV['ZIKULA_INSTALLED'], ZikulaKernel::VERSION, '<')) { |
31
|
|
|
self::loadParametersFromFile(); |
32
|
|
|
$versionChecker = new ZikulaRequirements(); |
33
|
|
|
$versionChecker->runSymfonyChecks(self::$parameters); |
34
|
|
|
if (empty($versionChecker->requirementsErrors)) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// formatting for both HTML and CLI display |
39
|
|
|
if ('cli' !== PHP_SAPI) { |
40
|
|
|
echo '<html><body><pre>'; |
41
|
|
|
} |
42
|
|
|
echo 'The following errors were discovered when checking the' . PHP_EOL . 'Zikula Core system/environment requirements:' . PHP_EOL; |
43
|
|
|
echo '******************************************************' . PHP_EOL . PHP_EOL; |
44
|
|
|
foreach ($versionChecker->requirementsErrors as $error) { |
45
|
|
|
echo $error . PHP_EOL; |
46
|
|
|
} |
47
|
|
|
if ('cli' !== PHP_SAPI) { |
48
|
|
|
echo '</pre></body></html>'; |
49
|
|
|
} |
50
|
|
|
die(); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function getParameter($name) |
55
|
|
|
{ |
56
|
|
|
self::loadParametersFromFile(); |
57
|
|
|
|
58
|
|
|
return self::$parameters[$name]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private static function loadParametersFromFile(): void |
62
|
|
|
{ |
63
|
|
|
if (is_array(self::$parameters)) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
$projectDir = dirname(__DIR__, 4); // should work when Bundle in vendor too |
67
|
|
|
$kernelConfig = Yaml::parse(file_get_contents(realpath($projectDir . '/config/services.yaml'))); |
68
|
|
|
if (is_readable($file = $projectDir . '/config/services_custom.yaml')) { |
69
|
|
|
$kernelConfig = array_merge($kernelConfig, Yaml::parse(file_get_contents($file))); |
70
|
|
|
} |
71
|
|
|
$parameters = $kernelConfig['parameters']; |
72
|
|
|
$parameters['kernel.project_dir'] = $projectDir; |
73
|
|
|
|
74
|
|
|
self::$parameters = $parameters; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.