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