1 | <?php |
||
21 | class Producer implements ProducerInterface |
||
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 | * @var AMQPChannel |
||
49 | */ |
||
50 | private $channel; |
||
51 | |||
52 | /** |
||
53 | * Simple fluent constructor to avoid weird-looking constructions like |
||
54 | * |
||
55 | * ```php |
||
56 | * $qos = (new Producer())->toExchange(); |
||
57 | * ``` |
||
58 | * |
||
59 | * @param AbstractConnection $connection |
||
60 | * @return Producer $this |
||
61 | */ |
||
62 | public static function factory(AbstractConnection $connection) |
||
66 | |||
67 | /** |
||
68 | * Producer constructor. |
||
69 | * @param AbstractConnection $connection |
||
70 | */ |
||
71 | public function __construct(AbstractConnection $connection) |
||
79 | |||
80 | /** |
||
81 | * @param Exchange $exchange |
||
82 | * @return Producer $this |
||
83 | */ |
||
84 | public function withExchange(Exchange $exchange) |
||
91 | |||
92 | /** |
||
93 | * @param Queue $queue |
||
94 | * @return Producer $this |
||
95 | */ |
||
96 | public function withQueue(Queue $queue) |
||
103 | |||
104 | /** |
||
105 | * @param \Closure|callable $formatter |
||
106 | * @return Producer $this |
||
107 | * @throws ProducerNotProperlyConfigured |
||
108 | */ |
||
109 | public function withFormatter($formatter) |
||
118 | |||
119 | /** |
||
120 | * @param mixed $payload |
||
121 | * @todo: maybe add properties array as second parameter |
||
122 | * @throws ProducerNotProperlyConfigured if queue nor exchange not given. |
||
123 | */ |
||
124 | public function produce($payload) |
||
139 | |||
140 | /** |
||
141 | * Returns `true` if producer is properly configured. Throws exception otherwise. |
||
142 | * Function is public just because Consumer needs to check if given producer configured before consuming the queue. |
||
143 | * |
||
144 | * @return bool |
||
145 | * @throws ProducerNotProperlyConfigured |
||
146 | */ |
||
147 | public function selfCheck() |
||
155 | |||
156 | /** |
||
157 | * @return AMQPChannel |
||
158 | * @throws ProducerNotProperlyConfigured |
||
159 | */ |
||
160 | protected function getChannel() |
||
201 | |||
202 | /** |
||
203 | * @param mixed $payload |
||
204 | * @return AMQPMessage |
||
205 | */ |
||
206 | protected function createMessage($payload) |
||
210 | |||
211 | /** |
||
212 | * @return bool |
||
213 | */ |
||
214 | protected function isExchange() |
||
218 | } |
||
219 |