| 1 | <?php |
||
| 8 | class SocketCluster |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var WebSocket\Client |
||
| 12 | */ |
||
| 13 | protected $websocket; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | protected $error; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Construct |
||
| 22 | * |
||
| 23 | * @param WebSocket\Client $websocket |
||
| 24 | */ |
||
| 25 | 3 | public function __construct(Client $websocket) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Publish Channel |
||
| 32 | * |
||
| 33 | * @param string $channel |
||
| 34 | * @param mixed $data |
||
| 35 | * @param Closure|null $callback |
||
| 36 | * |
||
| 37 | * @return boolean |
||
| 38 | */ |
||
| 39 | 2 | public function publish($channel, $data, Closure $callback = null) |
|
| 40 | { |
||
| 41 | $pubData = [ |
||
| 42 | 2 | 'channel' => $channel, |
|
| 43 | 2 | 'data' => $data, |
|
| 44 | 2 | ]; |
|
| 45 | |||
| 46 | 2 | return $this->emit('#publish', $pubData, $callback); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Emit Event |
||
| 51 | * |
||
| 52 | * @param string $event |
||
| 53 | * @param array $data |
||
| 54 | * @param Closure|null $callback |
||
| 55 | * |
||
| 56 | * @return boolean |
||
| 57 | */ |
||
| 58 | 2 | protected function emit($event, array $data, Closure $callback = null) |
|
| 59 | { |
||
| 60 | try { |
||
| 61 | $eventData = [ |
||
| 62 | 2 | 'event' => $event, |
|
| 63 | 2 | 'data' => $data, |
|
| 64 | 2 | ]; |
|
| 65 | |||
| 66 | 2 | $sendData = (string) @json_encode($eventData); |
|
| 67 | |||
| 68 | 2 | $this->websocket->send($sendData); |
|
| 69 | |||
| 70 | 1 | $this->error = null; |
|
| 71 | |||
| 72 | 1 | return true; |
|
| 73 | |||
| 74 | 1 | } catch (Exception $e) { |
|
| 75 | 1 | $this->error = $e->getMessage(); |
|
| 76 | 1 | return false; |
|
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Get Error |
||
| 82 | * |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | 1 | public function error() |
|
| 89 | } |
||
| 90 |
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..