1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\SelfDiagnosis\Checks; |
4
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\Filesystem; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
|
8
|
|
|
class PhpExtensionsAreInstalled implements Check |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
const EXT = 'ext-'; |
12
|
|
|
|
13
|
|
|
/** @var Filesystem */ |
14
|
|
|
private $filesystem; |
15
|
|
|
|
16
|
|
|
public function __construct(Filesystem $filesystem) |
17
|
|
|
{ |
18
|
|
|
$this->filesystem = $filesystem; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** @var Collection */ |
22
|
|
|
private $extensions; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The name of the check. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function name(): string |
30
|
|
|
{ |
31
|
|
|
return 'The required PHP extensions are installed'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The error message to display in case the check does not pass. |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function message(): string |
40
|
|
|
{ |
41
|
|
|
return 'The following extensions are missing: ' . PHP_EOL . $this->extensions->implode(PHP_EOL); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Perform the actual verification of this check. |
46
|
|
|
* |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
public function check(): bool |
50
|
|
|
{ |
51
|
|
|
$this->extensions = Collection::make([ |
52
|
|
|
'openssl', |
53
|
|
|
'PDO', |
54
|
|
|
'mbstring', |
55
|
|
|
'tokenizer', |
56
|
|
|
'xml', |
57
|
|
|
'ctype', |
58
|
|
|
'json' |
59
|
|
|
]); |
60
|
|
|
$this->extensions = $this->extensions->merge($this->getExtensionsRequiredInComposerFile()); |
61
|
|
|
$this->extensions = $this->extensions->unique(); |
62
|
|
|
$this->extensions = $this->extensions->reject(function ($ext) { |
63
|
|
|
return extension_loaded($ext); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
return $this->extensions->isEmpty(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
72
|
|
|
*/ |
73
|
|
|
public function getExtensionsRequiredInComposerFile() |
74
|
|
|
{ |
75
|
|
|
$installedPackages = json_decode($this->filesystem->get(base_path('vendor/composer/installed.json')), true); |
76
|
|
|
|
77
|
|
|
$extensions = []; |
78
|
|
|
foreach ($installedPackages as $installedPackage) { |
79
|
|
|
$filtered = array_where(array_keys(array_get($installedPackage, 'require', [])), function ($value, $key) { |
|
|
|
|
80
|
|
|
return starts_with($value, self::EXT); |
81
|
|
|
}); |
82
|
|
|
foreach ($filtered as $extension) { |
83
|
|
|
$extensions[] = str_replace_first(self::EXT, '', $extension); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
return array_unique($extensions); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.