1 | <?php |
||
30 | class Connection implements ConnectionInterface, WireSubscriberInterface, LoggerAwareInterface |
||
31 | { |
||
32 | use LoggerAwareTrait; |
||
33 | |||
34 | const STATUS_CLOSED = 0; |
||
35 | const STATUS_READY = 1; |
||
36 | const STATUS_BLOCKED = 2; |
||
37 | |||
38 | /** |
||
39 | * @var Url |
||
40 | */ |
||
41 | private $url; |
||
42 | |||
43 | /** |
||
44 | * @var WireInterface |
||
45 | */ |
||
46 | private $wire; |
||
47 | |||
48 | /** |
||
49 | * @var AuthenticatorInterface |
||
50 | */ |
||
51 | private $authenticator; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | private $status; |
||
57 | |||
58 | /** |
||
59 | * @var Channel[] |
||
60 | */ |
||
61 | private $channels = []; |
||
62 | |||
63 | /** |
||
64 | * @var array |
||
65 | */ |
||
66 | private $capabilities = []; |
||
67 | |||
68 | /** |
||
69 | * @param Url|string $url |
||
70 | * @param WireInterface $wire |
||
71 | * @param AuthenticatorInterface $authenticator |
||
72 | */ |
||
73 | 31 | public function __construct(Url $url, WireInterface $wire, AuthenticatorInterface $authenticator = null) |
|
80 | |||
81 | /** |
||
82 | * Connection status. See STATUS_* constants for possible values. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 4 | public function getStatus() |
|
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | 19 | public function open() |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 19 | public function channel($id = null) |
|
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | 7 | public function close($code = 0, $reason = '') |
|
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | 1 | public function isSupported($capability) |
|
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | 10 | public function serve($blocking = true) |
|
173 | |||
174 | /** |
||
175 | * Sends frame to the service channel (#0). |
||
176 | * |
||
177 | * @param Frame $frame |
||
178 | * |
||
179 | * @return $this |
||
180 | */ |
||
181 | 26 | private function send(Frame $frame) |
|
187 | |||
188 | /** |
||
189 | * Wait for a frame in the service channel (#0). |
||
190 | * |
||
191 | * @param string|array $type |
||
192 | * |
||
193 | * @return Frame |
||
194 | */ |
||
195 | 20 | private function wait($type) |
|
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | 26 | public function dispatch(Frame $frame) |
|
217 | |||
218 | /** |
||
219 | * This frame is the first frame received from server. |
||
220 | * It provides server details and requests client credentials. |
||
221 | * |
||
222 | * @param ConnectionStart $frame |
||
223 | */ |
||
224 | 20 | private function onConnectionStart(ConnectionStart $frame) |
|
256 | |||
257 | /** |
||
258 | * This frame is received to setup connection preferences, like max frame size, |
||
259 | * max number of channel and heartbeat delay. |
||
260 | * |
||
261 | * Values in the request can be lowered by client. |
||
262 | * |
||
263 | * @param ConnectionTune $frame |
||
264 | */ |
||
265 | private function onConnectionTune(ConnectionTune $frame) |
||
280 | |||
281 | /** |
||
282 | * This frame is received once server decide to close connection, normally because an unrecoverable error occur. |
||
283 | * |
||
284 | * @param ConnectionClose $frame |
||
285 | * |
||
286 | * @throws AMQPException |
||
287 | */ |
||
288 | 3 | private function onConnectionClose(ConnectionClose $frame) |
|
299 | |||
300 | /** |
||
301 | * This frame is received once server decide to suspend connection, for example because server |
||
302 | * run out of memory and can not provide service for the connection. When this happen consumer |
||
303 | * suppose to suspend all activities until connection.unblocked is received. |
||
304 | * |
||
305 | * @param ConnectionBlocked $frame |
||
306 | */ |
||
307 | 1 | private function onConnectionBlocked(ConnectionBlocked $frame) |
|
311 | |||
312 | /** |
||
313 | * This frame is received once connection returns back to normal state after being suspended. |
||
314 | * See onConnectionBlocked above. |
||
315 | * |
||
316 | * @param ConnectionUnblocked $frame |
||
317 | */ |
||
318 | 1 | private function onConnectionUnblocked(ConnectionUnblocked $frame) |
|
322 | } |
||
323 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.