1 | <?php |
||
26 | class Connection extends AbstractConnection |
||
27 | { |
||
28 | 3 | public function __construct( |
|
40 | |||
41 | private function initListeners() |
||
42 | { |
||
43 | 3 | $this->stream->on('data', function ($data) { |
|
44 | 2 | $this->processData($data); |
|
45 | 3 | }); |
|
46 | 3 | $this->stream->once('end', function() { |
|
47 | 1 | $this->getHandler()->onDisconnect($this); |
|
48 | 3 | }); |
|
49 | 3 | $this->stream->on('error', function ($data) { |
|
50 | $this->error($data); |
||
51 | 3 | }); |
|
52 | 3 | } |
|
53 | |||
54 | 2 | private function processData($data) |
|
55 | { |
||
56 | try { |
||
57 | 2 | if (!$this->handshakeDone) { |
|
58 | 2 | $this->processHandshake($data); |
|
59 | } else { |
||
60 | 2 | $this->processMessage($data); |
|
61 | } |
||
62 | |||
63 | 2 | return; |
|
64 | } catch (WebsocketException $e) { |
||
65 | $this->messageProcessor->close($this->stream); |
||
66 | $this->logger->notice('Connection to ' . $this->getIp() . ' closed with error : ' . $e->getMessage()); |
||
67 | $this->getHandler()->onError($e, $this); |
||
68 | } catch (NoHandlerException $e) { |
||
69 | $this->getLogger()->info(sprintf('No handler found for uri %s. Connection closed.', $this->uri)); |
||
70 | $this->close(Frame::CLOSE_WRONG_DATA); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * This method build a message and buffer data in case of incomplete data. |
||
76 | * |
||
77 | * @param string $data |
||
78 | */ |
||
79 | 2 | protected function processMessage(string $data) |
|
110 | |||
111 | public function write($frame, int $opCode = Frame::OP_TEXT) |
||
119 | |||
120 | /** |
||
121 | * @param mixed $data |
||
122 | */ |
||
123 | protected function error($data) |
||
129 | |||
130 | /** |
||
131 | * If it's a new client, we need to make some special actions named the handshake. |
||
132 | * |
||
133 | * @param string $data |
||
134 | */ |
||
135 | 2 | protected function processHandshake(string $data) |
|
151 | |||
152 | /** |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getIp() |
||
159 | } |
||
160 |
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.