-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCompositeQueueProvider.php
More file actions
61 lines (52 loc) · 1.36 KB
/
CompositeQueueProvider.php
File metadata and controls
61 lines (52 loc) · 1.36 KB
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
<?php
declare(strict_types=1);
namespace Yiisoft\Queue\Provider;
use BackedEnum;
use Yiisoft\Queue\QueueInterface;
use function array_merge;
use function array_unique;
use function array_values;
/**
* Composite queue provider.
*/
final class CompositeQueueProvider implements QueueProviderInterface
{
/**
* @var QueueProviderInterface[]
*/
private readonly array $providers;
/**
* @param QueueProviderInterface ...$providers Queue providers to use.
*/
public function __construct(
QueueProviderInterface ...$providers,
) {
$this->providers = $providers;
}
public function get(string|BackedEnum $name): QueueInterface
{
foreach ($this->providers as $provider) {
if ($provider->has($name)) {
return $provider->get($name);
}
}
throw new QueueNotFoundException($name);
}
public function has(string|BackedEnum $name): bool
{
foreach ($this->providers as $provider) {
if ($provider->has($name)) {
return true;
}
}
return false;
}
public function getNames(): array
{
$names = [];
foreach ($this->providers as $provider) {
$names[] = $provider->getNames();
}
return array_values(array_unique(array_merge(...$names)));
}
}