1 | <?php |
||
28 | class Connection implements ConnectionInterface |
||
29 | { |
||
30 | const CHUNK_SIZE = 65536; |
||
31 | |||
32 | /** Supported socket types. */ |
||
33 | const SOCK_TPC = 0; |
||
34 | const SOCK_UNIX = 1; |
||
35 | |||
36 | /** @var string */ |
||
37 | private $address; |
||
38 | |||
39 | /** @var int|null */ |
||
40 | private $port; |
||
41 | |||
42 | /** @var int */ |
||
43 | private $type; |
||
44 | |||
45 | /** @var resource|null */ |
||
46 | private $socket; |
||
47 | |||
48 | /** |
||
49 | * Example: |
||
50 | * $conn = new Connection("localhost", 7000); |
||
51 | * |
||
52 | * $conn = new Connection("/tmp/rpc.sock", null, Socket::UNIX_SOCKET); |
||
53 | * |
||
54 | * @param string $address Localhost, ip address or hostname. |
||
55 | * @param int|null $port Ignored for UNIX sockets. |
||
56 | * @param int $type Default: TPC_SOCKET |
||
57 | * |
||
58 | * @throws \Spiral\Goridge\Exceptions\InvalidArgumentException |
||
59 | */ |
||
60 | public function __construct(string $address, int $port = null, int $type = self::SOCK_TPC) |
||
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getAddress(): string |
||
94 | |||
95 | /** |
||
96 | * @return int|null |
||
97 | */ |
||
98 | public function getPort(): ? int |
||
102 | |||
103 | /** |
||
104 | * @return int |
||
105 | */ |
||
106 | public function getType(): int |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isConnected(): bool |
||
118 | |||
119 | /** |
||
120 | * Send payload message to another party. |
||
121 | * |
||
122 | * @param string|binary $payload |
||
123 | * @param int $flags |
||
124 | * |
||
125 | * @return self |
||
126 | * |
||
127 | * @throws \Spiral\Goridge\Exceptions\MessageException When message can not be send. |
||
128 | */ |
||
129 | public function send($payload, int $flags = self::KEEP_CONNECTION): self |
||
147 | |||
148 | /** |
||
149 | * Receive message from another party in sync/blocked mode. Message can be null. |
||
150 | * |
||
151 | * @param int $flags Response flags. |
||
152 | * |
||
153 | * @return null|string |
||
154 | * |
||
155 | * @throws \Spiral\Goridge\Exceptions\TransportException When unable to connect or maintain |
||
156 | * socket. |
||
157 | * @throws \Spiral\Goridge\Exceptions\MessageException When messages can not be retrieved. |
||
158 | */ |
||
159 | public function receiveSync(int & $flags = null): ? string |
||
191 | |||
192 | /** |
||
193 | * Ensure socket connection. Returns true if socket successfully connected |
||
194 | * or have already been connected. |
||
195 | * |
||
196 | * @return bool |
||
197 | * |
||
198 | * @throws \Spiral\Goridge\Exceptions\TransportException |
||
199 | * @throws \Error When sockets are used in unsupported environment. |
||
200 | */ |
||
201 | public function connect(): bool |
||
218 | |||
219 | /** |
||
220 | * Close connection. |
||
221 | * |
||
222 | * @throws \Spiral\Goridge\Exceptions\TransportException |
||
223 | */ |
||
224 | public function close() |
||
233 | |||
234 | /** |
||
235 | * Destruct connection and disconnect. |
||
236 | */ |
||
237 | public function __destruct() |
||
243 | |||
244 | /** |
||
245 | * @return string |
||
246 | */ |
||
247 | public function __toString(): string |
||
255 | |||
256 | /** |
||
257 | * @return array Prefix [flag, length] |
||
258 | * |
||
259 | * @throws \Spiral\Goridge\Exceptions\PrefixException |
||
260 | */ |
||
261 | private function fetchPrefixSync(): array |
||
273 | |||
274 | /** |
||
275 | * @return resource |
||
276 | * @throws \Error |
||
277 | */ |
||
278 | private function createSocket(): resource |
||
291 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..