-
Notifications
You must be signed in to change notification settings - Fork 110
/
PhpExtensionsAreInstalled.php
90 lines (76 loc) · 2.48 KB
/
PhpExtensionsAreInstalled.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace BeyondCode\SelfDiagnosis\Checks;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
class PhpExtensionsAreInstalled implements Check
{
const EXT = 'ext-';
/** @var Filesystem */
private $filesystem;
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}
/** @var Collection */
private $extensions;
/**
* The name of the check.
*
* @param array $config
* @return string
*/
public function name(array $config): string
{
return trans('self-diagnosis::checks.php_extensions_are_installed.name');
}
/**
* The error message to display in case the check does not pass.
*
* @param array $config
* @return string
*/
public function message(array $config): string
{
return trans('self-diagnosis::checks.php_extensions_are_installed.message', [
'extensions' => $this->extensions->implode(PHP_EOL),
]);
}
/**
* Perform the actual verification of this check.
*
* @param array $config
* @return bool
*/
public function check(array $config): bool
{
$this->extensions = Collection::make(Arr::get($config, 'extensions', []));
if (Arr::get($config, 'include_composer_extensions', false)) {
$this->extensions = $this->extensions->merge($this->getExtensionsRequiredInComposerFile());
$this->extensions = $this->extensions->unique();
}
$this->extensions = $this->extensions->reject(function ($ext) {
return extension_loaded($ext);
});
return $this->extensions->isEmpty();
}
/**
* @return array
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function getExtensionsRequiredInComposerFile()
{
$installedPackages = json_decode($this->filesystem->get(base_path('vendor/composer/installed.json')), true);
$extensions = [];
foreach ($installedPackages as $installedPackage) {
$filtered = Arr::where(array_keys(Arr::get($installedPackage, 'require', [])), function ($value, $key) {
return Str::startsWith($value, self::EXT);
});
foreach ($filtered as $extension) {
$extensions[] = Str::replaceFirst(self::EXT, '', $extension);
}
}
return array_unique($extensions);
}
}