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