1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\SelfDiagnosis\Checks; |
4
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\Filesystem; |
6
|
|
|
use Composer\Semver\Semver; |
7
|
|
|
use Illuminate\Support\Arr; |
8
|
|
|
|
9
|
|
|
class CorrectPhpVersionIsInstalled implements Check |
10
|
|
|
{ |
11
|
|
|
/** @var Filesystem */ |
12
|
|
|
private $filesystem; |
13
|
|
|
|
14
|
16 |
|
public function __construct(Filesystem $filesystem) |
15
|
|
|
{ |
16
|
16 |
|
$this->filesystem = $filesystem; |
17
|
16 |
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The name of the check. |
21
|
|
|
* |
22
|
|
|
* @param array $config |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function name(array $config): string |
26
|
|
|
{ |
27
|
|
|
return trans('self-diagnosis::checks.correct_php_version_is_installed.name'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Perform the actual verification of this check. |
32
|
|
|
* |
33
|
|
|
* @param array $config |
34
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
35
|
|
|
* @return bool |
36
|
|
|
*/ |
37
|
12 |
|
public function check(array $config): bool |
38
|
|
|
{ |
39
|
|
|
// we dont use the phpversion function because that adds more data to the number (Like: -1+ubuntu16.04) |
40
|
|
|
// that conflicts with the semver check |
41
|
12 |
|
return Semver::satisfies( |
42
|
12 |
|
PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION, |
43
|
12 |
|
$this->getRequiredPhpConstraint() |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The error message to display in case the check does not pass. |
49
|
|
|
* |
50
|
|
|
* @param array $config |
51
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function message(array $config): string |
55
|
|
|
{ |
56
|
|
|
return trans('self-diagnosis::checks.correct_php_version_is_installed.message', [ |
57
|
|
|
'required' => $this->getRequiredPhpConstraint(), |
58
|
|
|
'used' => phpversion(), |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return mixed |
64
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
65
|
|
|
*/ |
66
|
16 |
|
public function getRequiredPhpConstraint() |
67
|
|
|
{ |
68
|
16 |
|
$composer = json_decode($this->filesystem->get(base_path('composer.json')), true); |
69
|
16 |
|
return Arr::get($composer, 'require.php'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|