1 | <?php |
||
23 | class Producer |
||
24 | { |
||
25 | /** |
||
26 | * @var callable |
||
27 | */ |
||
28 | private $formatter; |
||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | private $isExchange; |
||
34 | |||
35 | /** |
||
36 | * @var Queue |
||
37 | */ |
||
38 | protected $queue; |
||
39 | |||
40 | /** |
||
41 | * @var Exchange |
||
42 | */ |
||
43 | protected $exchange; |
||
44 | |||
45 | /** |
||
46 | * @var AbstractConnection |
||
47 | */ |
||
48 | private $connection; |
||
49 | |||
50 | /** |
||
51 | * Simple fluent constructor to avoid weird-looking constructions like |
||
52 | * |
||
53 | * ```php |
||
54 | * $qos = (new Producer())->toExchange(); |
||
55 | * ``` |
||
56 | * |
||
57 | * @param AbstractConnection $connection |
||
58 | * @return Producer |
||
59 | */ |
||
60 | public static function factory(AbstractConnection $connection) |
||
64 | |||
65 | /** |
||
66 | * Producer constructor. |
||
67 | * @param AbstractConnection $connection |
||
68 | */ |
||
69 | public function __construct(AbstractConnection $connection) |
||
77 | |||
78 | /** |
||
79 | * @param Exchange $exchange |
||
80 | * @return Producer $this |
||
81 | */ |
||
82 | public function withExchange(Exchange $exchange) |
||
88 | |||
89 | /** |
||
90 | * @param Queue $queue |
||
91 | * @return Producer $this |
||
92 | */ |
||
93 | public function withQueue(Queue $queue) |
||
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | protected function isExchange() |
||
107 | |||
108 | /** |
||
109 | * @param \Closure|callable $formatter |
||
110 | * @return Producer $this |
||
111 | * @throws \AmqpWorkers\Exception\ProducerNotProperlyConfigured |
||
112 | */ |
||
113 | public function withFormatter($formatter) |
||
122 | |||
123 | /** |
||
124 | * @param mixed $payload |
||
125 | * @todo: maybe add properties array as second parameter |
||
126 | * @throws \AmqpWorkers\Exception\ProducerNotProperlyConfigured if queue nor exchange not given. |
||
127 | */ |
||
128 | public function produce($payload) |
||
143 | |||
144 | /** |
||
145 | * @return AMQPChannel |
||
146 | * @todo: declare queue only once? |
||
147 | * @throws \AmqpWorkers\Exception\ProducerNotProperlyConfigured |
||
148 | */ |
||
149 | protected function getChannel() |
||
190 | |||
191 | /** |
||
192 | * @param mixed $payload |
||
193 | * @return AMQPMessage |
||
194 | */ |
||
195 | protected function createMessage($payload) |
||
199 | } |
||
200 |