|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Facade\Ignition\SolutionProviders; |
|
4
|
|
|
|
|
5
|
|
|
use Throwable; |
|
6
|
|
|
use LogicException; |
|
7
|
|
|
use Facade\IgnitionContracts\BaseSolution; |
|
8
|
|
|
use Facade\IgnitionContracts\HasSolutionsForThrowable; |
|
9
|
|
|
|
|
10
|
|
|
class RedisClientNotInstalledSolutionProvider implements HasSolutionsForThrowable |
|
11
|
|
|
{ |
|
12
|
|
|
public function canSolve(Throwable $throwable): bool |
|
13
|
|
|
{ |
|
14
|
|
|
if (! $throwable instanceof LogicException) { |
|
15
|
|
|
return false; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
return true; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function getSolutions(Throwable $throwable): array |
|
22
|
|
|
{ |
|
23
|
|
|
$client = config('database.redis.client'); |
|
24
|
|
|
[$message, $description] = $this->getSolutionMessage($client); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
return [ |
|
27
|
|
|
BaseSolution::create($message) |
|
28
|
|
|
->setSolutionDescription($description), |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function getSolutionMessage(string $client): array |
|
33
|
|
|
{ |
|
34
|
|
|
$predis = file_exists(base_path('vendor/predis/predis')); |
|
35
|
|
|
$phpredis = file_exists(base_path('vendor/phpredis/phpredis')); |
|
36
|
|
|
|
|
37
|
|
|
if ($client === 'predis') { |
|
38
|
|
|
if ($predis === false && $phpredis === true) { |
|
39
|
|
|
return [ |
|
40
|
|
|
'predis is set as client, but it wasn\'t installed.', |
|
41
|
|
|
'either run `composer require predis/predis` or default to phpredis which is installed', |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($predis === true && $phpredis === false) { |
|
47
|
|
|
return [ |
|
48
|
|
|
'phpredis is set as client, but it wasn\'t installed.', |
|
49
|
|
|
'either run `composer require phpredis/phpredis` or set the `REDIS_CLIENT` to predis in your `.env`.', |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return [ |
|
54
|
|
|
'there was no client installed.', |
|
55
|
|
|
'run `composer require phpredis/phpredis`', |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.