1 | <?php |
||
21 | class Producer |
||
22 | { |
||
23 | /** |
||
24 | * @var callable |
||
25 | */ |
||
26 | private $formatter; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $isExchange; |
||
32 | |||
33 | /** |
||
34 | * @var Queue |
||
35 | */ |
||
36 | protected $queue; |
||
37 | |||
38 | /** |
||
39 | * @var Exchange |
||
40 | */ |
||
41 | protected $exchange; |
||
42 | |||
43 | /** |
||
44 | * @var AbstractConnection |
||
45 | */ |
||
46 | private $connection; |
||
47 | |||
48 | /** |
||
49 | * Simple fluent constructor to avoid weird-looking constructions like |
||
50 | * |
||
51 | * ```php |
||
52 | * $qos = (new Producer())->toExchange(); |
||
53 | * ``` |
||
54 | * |
||
55 | * @param AbstractConnection $connection |
||
56 | * @return Producer $this |
||
57 | */ |
||
58 | public static function factory(AbstractConnection $connection) |
||
62 | |||
63 | /** |
||
64 | * Producer constructor. |
||
65 | * @param AbstractConnection $connection |
||
66 | */ |
||
67 | public function __construct(AbstractConnection $connection) |
||
75 | |||
76 | /** |
||
77 | * @param Exchange $exchange |
||
78 | * @return Producer $this |
||
79 | */ |
||
80 | public function withExchange(Exchange $exchange) |
||
86 | |||
87 | /** |
||
88 | * @param Queue $queue |
||
89 | * @return Producer $this |
||
90 | */ |
||
91 | public function withQueue(Queue $queue) |
||
97 | |||
98 | /** |
||
99 | * @param \Closure|callable $formatter |
||
100 | * @return Producer $this |
||
101 | * @throws ProducerNotProperlyConfigured |
||
102 | */ |
||
103 | public function withFormatter($formatter) |
||
112 | |||
113 | /** |
||
114 | * @param mixed $payload |
||
115 | * @todo: maybe add properties array as second parameter |
||
116 | * @throws ProducerNotProperlyConfigured if queue nor exchange not given. |
||
117 | */ |
||
118 | public function produce($payload) |
||
133 | |||
134 | /** |
||
135 | * Returns `true` if producer is properly configured. Throws exception otherwise. |
||
136 | * Function is public just because Consumer needs to check if given producer configured before consuming the queue. |
||
137 | * |
||
138 | * @return bool |
||
139 | * @throws ProducerNotProperlyConfigured |
||
140 | */ |
||
141 | public function selfCheck() |
||
149 | |||
150 | /** |
||
151 | * @return AMQPChannel |
||
152 | * @throws ProducerNotProperlyConfigured |
||
153 | */ |
||
154 | protected function getChannel() |
||
193 | |||
194 | /** |
||
195 | * @param mixed $payload |
||
196 | * @return AMQPMessage |
||
197 | */ |
||
198 | protected function createMessage($payload) |
||
202 | |||
203 | /** |
||
204 | * @return bool |
||
205 | */ |
||
206 | protected function isExchange() |
||
210 | } |
||
211 |