1 | <?php |
||
19 | class Wire implements WireInterface, LoggerAwareInterface |
||
20 | { |
||
21 | const PROTOCOL_HEADER = "AMQP\x00\x00\x09\x01"; |
||
22 | const FRAME_ENDING = "\xCE"; |
||
23 | |||
24 | use LoggerAwareTrait; |
||
25 | |||
26 | /** |
||
27 | * @var IOInterface |
||
28 | */ |
||
29 | private $io; |
||
30 | |||
31 | /** |
||
32 | * @var WireSubscriberInterface[] |
||
33 | */ |
||
34 | private $subscribers = []; |
||
35 | |||
36 | /** |
||
37 | * @var HeartbeatInterface |
||
38 | */ |
||
39 | private $heartbeat; |
||
40 | |||
41 | /** |
||
42 | * @var int |
||
43 | */ |
||
44 | private $frameMax; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | private $buffer; |
||
50 | |||
51 | /** |
||
52 | * @param IOInterface $io |
||
53 | */ |
||
54 | 33 | public function __construct(IOInterface $io) |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | 19 | public function open(Url $url) |
|
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 28 | public function next($blocking = true) |
|
101 | |||
102 | /** |
||
103 | * Read next chunk of the data from the buffer. |
||
104 | * |
||
105 | * @param bool $blocking |
||
106 | */ |
||
107 | 28 | private function read($blocking) |
|
111 | |||
112 | /** |
||
113 | * Tries to fetch next frame from reading buffer. |
||
114 | * Will return a Frame or null if there is not enough data in the buffer. |
||
115 | * |
||
116 | * @return Frame|null |
||
117 | * |
||
118 | * @throws InvalidFrameEndingException |
||
119 | */ |
||
120 | 28 | private function tryNext() |
|
151 | |||
152 | /** |
||
153 | * @param Frame $frame |
||
154 | */ |
||
155 | 23 | private function dispatch(Frame $frame) |
|
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | 22 | public function send(Frame $frame) |
|
175 | |||
176 | /** |
||
177 | * @param Frame $frame |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | 22 | private function chop(Frame $frame) |
|
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | 20 | public function wait($channel, $types) |
|
214 | |||
215 | /** |
||
216 | * @param Frame $frame |
||
217 | * @param int $channel |
||
218 | * @param array $types |
||
219 | * |
||
220 | * @return bool |
||
221 | */ |
||
222 | 20 | private function isFrameMatch(Frame $frame = null, $channel = 0, array $types = []) |
|
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | */ |
||
230 | 19 | public function subscribe($channel, WireSubscriberInterface $handler) |
|
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | */ |
||
240 | 19 | public function close() |
|
246 | |||
247 | /** |
||
248 | * @param HeartbeatInterface $heartbeat |
||
249 | * |
||
250 | * @return $this |
||
251 | */ |
||
252 | 20 | public function setHeartbeat(HeartbeatInterface $heartbeat) |
|
258 | |||
259 | /** |
||
260 | * @param int $frameMax |
||
261 | * |
||
262 | * @return $this |
||
263 | */ |
||
264 | 18 | public function setFrameMax($frameMax) |
|
270 | |||
271 | /** |
||
272 | * @param int $channel |
||
273 | * |
||
274 | * @return WireSubscriberInterface|null |
||
275 | */ |
||
276 | 23 | private function getSubscriber($channel) |
|
280 | |||
281 | /** |
||
282 | * @param Url $url |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | 19 | private function getProtocolForScheme(Url $url) |
|
290 | } |
||
291 |