|
1
|
|
|
<?php |
|
2
|
|
|
namespace NeedleProject\LaravelRabbitMq; |
|
3
|
|
|
|
|
4
|
|
|
use NeedleProject\LaravelRabbitMq\ConsumerInterface; |
|
5
|
|
|
use NeedleProject\LaravelRabbitMq\PublisherInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class Container |
|
9
|
|
|
* |
|
10
|
|
|
* @package NeedleProject\LaravelRabbitMq |
|
11
|
|
|
* @author Adrian Tilita <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Container |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
private $publishers = []; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
private $consumers = []; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $publisherName |
|
27
|
|
|
* @param PublisherInterface $entity |
|
28
|
|
|
* @return Container |
|
29
|
|
|
*/ |
|
30
|
|
|
public function addPublisher(string $publisherName, PublisherInterface $entity): Container |
|
31
|
|
|
{ |
|
32
|
|
|
$this->publishers[$publisherName] = $entity; |
|
33
|
|
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $publisherName |
|
38
|
|
|
* @return PublisherInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getPublisher(string $publisherName): PublisherInterface |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->publishers[$publisherName]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getPublishers(): array |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->publishers; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $publisherName |
|
55
|
|
|
* @return bool |
|
56
|
|
|
*/ |
|
57
|
|
|
public function hasPublisher(string $publisherName): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return isset($this->publishers[$publisherName]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $consumerName |
|
64
|
|
|
* @param ConsumerInterface $consumer |
|
65
|
|
|
* @return Container |
|
66
|
|
|
*/ |
|
67
|
|
|
public function addConsumer(string $consumerName, ConsumerInterface $consumer): Container |
|
68
|
|
|
{ |
|
69
|
|
|
$this->consumers[$consumerName] = $consumer; |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $consumerName |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getConsumer(string $consumerName) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->consumers[$consumerName]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getConsumers(): array |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->consumers; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param string $consumerName |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
|
|
public function hasConsumer(string $consumerName): bool |
|
95
|
|
|
{ |
|
96
|
|
|
return isset($this->consumers[$consumerName]); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|