1 | <?php |
||
37 | class Client extends Application implements ClientInterface |
||
38 | { |
||
39 | use TimersAware; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | const LOGO = <<<EOT |
||
45 | _____ _____ _ _ _ _____ |
||
46 | / ___/ | _ \ | | | | / / | ____| |
||
47 | | |___ | |_| | | | | |/ / | |__ |
||
48 | \___ \ | ___/ | | | |\ \ | __| |
||
49 | ___| | | | | | | | \ \ | |___ |
||
50 | /_____/ |_| |_| |_| \_\ |_____| |
||
51 | |||
52 | |||
53 | EOT; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | const NAME = 'Spike Client'; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $id; |
||
64 | |||
65 | /** |
||
66 | * @var Configuration |
||
67 | */ |
||
68 | protected $configuration; |
||
69 | |||
70 | /** |
||
71 | * @var LoopInterface |
||
72 | */ |
||
73 | protected $eventLoop; |
||
74 | |||
75 | /** |
||
76 | * @var DispatcherInterface |
||
77 | */ |
||
78 | protected $eventDispatcher; |
||
79 | |||
80 | /** |
||
81 | * @var ConnectionInterface |
||
82 | */ |
||
83 | protected $controlConnection; |
||
84 | |||
85 | /** |
||
86 | * @var \DateTimeInterface |
||
87 | */ |
||
88 | protected $activeAt; |
||
89 | |||
90 | /** |
||
91 | * @var WorkerInterface[]|Collection |
||
92 | */ |
||
93 | protected $workers; |
||
94 | |||
95 | /** |
||
96 | * @var Logger |
||
97 | */ |
||
98 | protected $logger; |
||
99 | |||
100 | /** |
||
101 | * @var bool |
||
102 | */ |
||
103 | protected $running = false; |
||
104 | |||
105 | /** |
||
106 | * Whether connect to server. |
||
107 | * @var bool |
||
108 | */ |
||
109 | protected $connected = false; |
||
110 | |||
111 | public function __construct(Configuration $configuration, LoopInterface $eventLoop = null) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function getHelp() |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | * |
||
132 | * @codeCoverageIgnore |
||
133 | */ |
||
134 | public function doRun(InputInterface $input, OutputInterface $output) |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function start() |
||
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | public function close() |
||
193 | |||
194 | |||
195 | protected function reset() |
||
207 | |||
208 | /** |
||
209 | * Reconnect if disconnect from server. |
||
210 | */ |
||
211 | public function handleDisconnectServer() |
||
216 | |||
217 | /** |
||
218 | * Handles the control connection. |
||
219 | * |
||
220 | * @param ConnectionInterface $connection |
||
221 | * @codeCoverageIgnore |
||
222 | */ |
||
223 | protected function handleControlConnection(ConnectionInterface $connection) |
||
257 | |||
258 | /** |
||
259 | * Request for auth. |
||
260 | * |
||
261 | * @param ConnectionInterface $connection |
||
262 | * @codeCoverageIgnore |
||
263 | */ |
||
264 | protected function sendAuthRequest(ConnectionInterface $connection) |
||
273 | |||
274 | /** |
||
275 | * @return Configuration |
||
276 | */ |
||
277 | public function getConfiguration() |
||
281 | |||
282 | /** |
||
283 | * {@inheritdoc} |
||
284 | */ |
||
285 | public function getControlConnection() |
||
289 | |||
290 | /** |
||
291 | * {@inheritdoc} |
||
292 | */ |
||
293 | public function getId() |
||
297 | |||
298 | /** |
||
299 | * {@inheritdoc} |
||
300 | */ |
||
301 | public function setId($id) |
||
305 | |||
306 | /** |
||
307 | * {@inheritdoc} |
||
308 | */ |
||
309 | public function getActiveAt() |
||
313 | |||
314 | /** |
||
315 | * {@inheritdoc} |
||
316 | */ |
||
317 | public function getEventDispatcher() |
||
321 | |||
322 | /** |
||
323 | * @param \DateTimeInterface $activeAt |
||
324 | */ |
||
325 | public function setActiveAt($activeAt) |
||
329 | |||
330 | /** |
||
331 | * @return LoopInterface |
||
332 | */ |
||
333 | public function getEventLoop() |
||
337 | |||
338 | /** |
||
339 | * @return Collection|WorkerInterface[] |
||
340 | */ |
||
341 | public function getWorkers() |
||
345 | |||
346 | /** |
||
347 | * @return Logger |
||
348 | */ |
||
349 | public function getLogger() |
||
353 | |||
354 | /** |
||
355 | * {@inheritdoc} |
||
356 | */ |
||
357 | protected function getDefaultCommands() |
||
364 | |||
365 | protected function initializeEvents() |
||
370 | |||
371 | /** |
||
372 | * Creates default timers. |
||
373 | * |
||
374 | * @codeCoverageIgnore |
||
375 | */ |
||
376 | protected function initializeTimers() |
||
380 | } |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: