1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the box project. |
5
|
|
|
* |
6
|
|
|
* (c) Kevin Herrera <[email protected]> |
7
|
|
|
* Théo Fidry <[email protected]> |
8
|
|
|
* |
9
|
|
|
* This source file is subject to the MIT license that is bundled |
10
|
|
|
* with this source code in the file LICENSE. |
11
|
|
|
*/ |
12
|
|
|
namespace _HumbugBox5addf3ce683e7\KevinGH\RequirementChecker; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The code in this file must be PHP 5.3+ compatible as is used to know if the application can be run. |
16
|
|
|
* |
17
|
|
|
* @private |
18
|
|
|
*/ |
19
|
|
|
final class Checker |
20
|
|
|
{ |
21
|
|
|
/** @var null|string */ |
22
|
|
|
private static $requirementsConfig; |
23
|
|
|
/** |
24
|
|
|
* @return bool |
25
|
|
|
*/ |
26
|
|
|
public static function checkRequirements() |
27
|
|
|
{ |
28
|
|
|
$requirements = self::retrieveRequirements(); |
29
|
|
|
$checkPassed = $requirements->evaluateRequirements(); |
30
|
|
|
$io = new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO(); |
31
|
|
|
self::printCheck($checkPassed, new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements); |
32
|
|
|
return $checkPassed; |
33
|
|
|
} |
34
|
|
|
public static function printCheck($checkPassed, \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Printer $printer, \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\RequirementCollection $requirements) |
35
|
|
|
{ |
36
|
|
|
if (\false === $checkPassed && \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) { |
37
|
|
|
// Override the default verbosity to output errors regardless of the verbosity asked by the user |
38
|
|
|
$printer->setVerbosity(\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE); |
39
|
|
|
} |
40
|
|
|
$verbosity = \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE; |
41
|
|
|
$iniPath = $requirements->getPhpIniPath(); |
42
|
|
|
$printer->title('Box Requirements Checker', $verbosity); |
43
|
|
|
$printer->printv('> Using PHP ', $verbosity); |
44
|
|
|
$printer->printvln(\PHP_VERSION, $verbosity, 'green'); |
45
|
|
|
$printer->printvln('> PHP is using the following php.ini file:', $verbosity); |
46
|
|
|
if ($iniPath) { |
47
|
|
|
$printer->printvln(' ' . $iniPath, $verbosity, 'green'); |
48
|
|
|
} else { |
49
|
|
|
$printer->printvln(' WARNING: No configuration file (php.ini) used by PHP!', $verbosity, 'yellow'); |
50
|
|
|
} |
51
|
|
|
$printer->printvln('', $verbosity); |
52
|
|
|
if (\count($requirements) > 0) { |
53
|
|
|
$printer->printvln('> Checking Box requirements:', $verbosity); |
54
|
|
|
$printer->printv(' ', $verbosity); |
55
|
|
|
} else { |
56
|
|
|
$printer->printvln('> No requirements found.', $verbosity); |
57
|
|
|
} |
58
|
|
|
$errorMessages = array(); |
59
|
|
|
foreach ($requirements->getRequirements() as $requirement) { |
60
|
|
|
if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) { |
61
|
|
|
if (\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) { |
62
|
|
|
$printer->printvln('✘ ' . $requirement->getTestMessage(), \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'red'); |
63
|
|
|
$printer->printv(' ', \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG); |
64
|
|
|
$errorMessages[] = $errorMessage; |
65
|
|
|
} else { |
66
|
|
|
$printer->printv('E', $verbosity, 'red'); |
67
|
|
|
$errorMessages[] = $errorMessage; |
68
|
|
|
} |
69
|
|
|
continue; |
70
|
|
|
} |
71
|
|
|
if (\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) { |
72
|
|
|
$printer->printvln('✔ ' . $requirement->getHelpText(), \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'green'); |
73
|
|
|
$printer->printv(' ', \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG); |
74
|
|
|
} else { |
75
|
|
|
$printer->printv('.', $verbosity, 'green'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
if (\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG !== $printer->getVerbosity() && \count($requirements) > 0) { |
79
|
|
|
$printer->printvln('', $verbosity); |
80
|
|
|
} |
81
|
|
|
if ($requirements->evaluateRequirements()) { |
82
|
|
|
$printer->block('OK', 'Your system is ready to run the application.', $verbosity, 'success'); |
83
|
|
|
} else { |
84
|
|
|
$printer->block('ERROR', 'Your system is not ready to run the application.', $verbosity, 'error'); |
85
|
|
|
$printer->title('Fix the following mandatory requirements:', $verbosity, 'red'); |
86
|
|
|
foreach ($errorMessages as $errorMessage) { |
87
|
|
|
$printer->printv(' * ' . $errorMessage, $verbosity); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
$printer->printvln('', $verbosity); |
91
|
|
|
} |
92
|
|
|
/** |
93
|
|
|
* @return RequirementCollection |
94
|
|
|
*/ |
95
|
|
|
private static function retrieveRequirements() |
96
|
|
|
{ |
97
|
|
|
if (null === self::$requirementsConfig) { |
98
|
|
|
self::$requirementsConfig = __DIR__ . '/../.requirements.php'; |
99
|
|
|
} |
100
|
|
|
$config = (require self::$requirementsConfig); |
101
|
|
|
$requirements = new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\RequirementCollection(); |
102
|
|
|
foreach ($config as $constraint) { |
103
|
|
|
\call_user_func_array(array($requirements, 'addRequirement'), $constraint); |
104
|
|
|
} |
105
|
|
|
return $requirements; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|