|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webparking\QueueEnsurer\Config; |
|
4
|
|
|
|
|
5
|
|
|
class ConfigReader |
|
6
|
|
|
{ |
|
7
|
|
|
/** @return array<string> */ |
|
8
|
7 |
|
public function getQueueNames(): array |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var array<string> $res */ |
|
11
|
7 |
|
$res = array_keys(config('queue-ensurer.queues')); |
|
12
|
|
|
|
|
13
|
7 |
|
return $res; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
6 |
|
public function getAmount(string $queueName): int |
|
17
|
|
|
{ |
|
18
|
6 |
|
$queueConfig = $this->getQueueConfig($queueName); |
|
19
|
|
|
|
|
20
|
6 |
|
if (\is_array($queueConfig)) { |
|
21
|
1 |
|
return (int) $queueConfig['amount']; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
5 |
|
return $queueConfig; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
3 |
|
public function getPhpPath(): string |
|
28
|
|
|
{ |
|
29
|
3 |
|
return config('queue-ensurer.php-path', 'php'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
3 |
|
public function getConnection(string $queueName): ?string |
|
33
|
|
|
{ |
|
34
|
3 |
|
$queueConfig = $this->getQueueConfig($queueName); |
|
35
|
|
|
|
|
36
|
3 |
|
if (\is_array($queueConfig) && \array_key_exists('connection', $queueConfig)) { |
|
37
|
1 |
|
return (string) $queueConfig['connection']; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
return null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
3 |
|
public function specifyQueue(string $queueName): bool |
|
44
|
|
|
{ |
|
45
|
3 |
|
$queueConfig = $this->getQueueConfig($queueName); |
|
46
|
|
|
|
|
47
|
3 |
|
if (\is_array($queueConfig) && \array_key_exists('specify-queue', $queueConfig)) { |
|
48
|
1 |
|
return (bool) $queueConfig['specify-queue']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
2 |
|
return config('queue-ensurer.defaults.specify-queue'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
3 |
|
public function getTimeout(string $queueName): int |
|
55
|
|
|
{ |
|
56
|
3 |
|
$queueConfig = $this->getQueueConfig($queueName); |
|
57
|
|
|
|
|
58
|
3 |
|
if (\is_array($queueConfig) && \array_key_exists('timeout', $queueConfig)) { |
|
59
|
1 |
|
return (int) $queueConfig['timeout']; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
return config('queue-ensurer.defaults.timeout'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
public function getSleep(string $queueName): int |
|
66
|
|
|
{ |
|
67
|
3 |
|
$queueConfig = $this->getQueueConfig($queueName); |
|
68
|
|
|
|
|
69
|
3 |
|
if (\is_array($queueConfig) && \array_key_exists('sleep', $queueConfig)) { |
|
70
|
1 |
|
return (int) $queueConfig['sleep']; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
return config('queue-ensurer.defaults.sleep'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
3 |
|
public function getTries(string $queueName): int |
|
77
|
|
|
{ |
|
78
|
3 |
|
$queueConfig = $this->getQueueConfig($queueName); |
|
79
|
|
|
|
|
80
|
3 |
|
if (\is_array($queueConfig) && \array_key_exists('tries', $queueConfig)) { |
|
81
|
1 |
|
return (int) $queueConfig['tries']; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
return config('queue-ensurer.defaults.tries'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return array<string,int|string>|int |
|
89
|
|
|
*/ |
|
90
|
6 |
|
private function getQueueConfig(string $queueName) |
|
91
|
|
|
{ |
|
92
|
6 |
|
return config('queue-ensurer.queues')[$queueName]; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|