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
|
5 |
|
public function addPublisher(string $publisherName, PublisherInterface $entity): Container |
31
|
|
|
{ |
32
|
5 |
|
$this->publishers[$publisherName] = $entity; |
33
|
5 |
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $publisherName |
38
|
|
|
* @return PublisherInterface |
39
|
|
|
*/ |
40
|
3 |
|
public function getPublisher(string $publisherName): PublisherInterface |
41
|
|
|
{ |
42
|
3 |
|
return $this->publishers[$publisherName]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
5 |
|
public function getPublishers(): array |
49
|
|
|
{ |
50
|
5 |
|
return $this->publishers; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $publisherName |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
4 |
|
public function hasPublisher(string $publisherName): bool |
58
|
|
|
{ |
59
|
4 |
|
return isset($this->publishers[$publisherName]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $consumerName |
64
|
|
|
* @param ConsumerInterface $consumer |
65
|
|
|
* @return Container |
66
|
|
|
*/ |
67
|
4 |
|
public function addConsumer(string $consumerName, ConsumerInterface $consumer): Container |
68
|
|
|
{ |
69
|
4 |
|
$this->consumers[$consumerName] = $consumer; |
70
|
4 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $consumerName |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
2 |
|
public function getConsumer(string $consumerName) |
78
|
|
|
{ |
79
|
2 |
|
return $this->consumers[$consumerName]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
4 |
|
public function getConsumers(): array |
86
|
|
|
{ |
87
|
4 |
|
return $this->consumers; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $consumerName |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
2 |
|
public function hasConsumer(string $consumerName): bool |
95
|
|
|
{ |
96
|
2 |
|
return isset($this->consumers[$consumerName]); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|