We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 9 | class Centrifuge implements CentrifugeContract |
||
| 10 | { |
||
| 11 | const API_PATH = '/api'; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var \GuzzleHttp\Client |
||
| 15 | */ |
||
| 16 | protected $httpClient; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | protected $config; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Create a new Centrifugo instance. |
||
| 25 | * |
||
| 26 | * @param array $config |
||
| 27 | * @param \GuzzleHttp\Client $httpClient |
||
| 28 | */ |
||
| 29 | public function __construct(array $config, HttpClient $httpClient) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Init centrifugo configuration. |
||
| 37 | * |
||
| 38 | * @param array $config |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | protected function initConfiguration(array $config) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Send message into channel. |
||
| 62 | * |
||
| 63 | * @param string $channel |
||
| 64 | * @param array $data |
||
| 65 | * @return mixed |
||
| 66 | */ |
||
| 67 | public function publish(string $channel, array $data) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Send message into multiple channel. |
||
| 77 | * |
||
| 78 | * @param array $channels |
||
| 79 | * @param array $data |
||
| 80 | * @return mixed |
||
| 81 | */ |
||
| 82 | public function broadcast(array $channels, array $data) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Get channel presence information (all clients currently subscribed on this channel). |
||
| 91 | * |
||
| 92 | * @param string $channel |
||
| 93 | * @return mixed |
||
| 94 | */ |
||
| 95 | public function presence(string $channel) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get channel presence information in short form. |
||
| 102 | * |
||
| 103 | * @param string $channel |
||
| 104 | * @return mixed |
||
| 105 | */ |
||
| 106 | public function presence_stats(string $channel) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get channel history information (list of last messages sent into channel). |
||
| 113 | * |
||
| 114 | * @param string $channel |
||
| 115 | * @return mixed |
||
| 116 | */ |
||
| 117 | public function history(string $channel) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Remove channel history information. |
||
| 124 | * |
||
| 125 | * @param string $channel |
||
| 126 | * @return mixed |
||
| 127 | */ |
||
| 128 | public function history_remove(string $channel) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Unsubscribe user from channel. |
||
| 137 | * |
||
| 138 | * @param string $channel |
||
| 139 | * @param string $user |
||
| 140 | * @return mixed |
||
| 141 | */ |
||
| 142 | public function unsubscribe(string $channel, string $user) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Disconnect user by its ID. |
||
| 152 | * |
||
| 153 | * @param string $user_id |
||
| 154 | * @return mixed |
||
| 155 | */ |
||
| 156 | public function disconnect(string $user_id) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Get channels information (list of currently active channels). |
||
| 163 | * |
||
| 164 | * @return mixed |
||
| 165 | */ |
||
| 166 | public function channels() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Get stats information about running server nodes. |
||
| 173 | * |
||
| 174 | * @return mixed |
||
| 175 | */ |
||
| 176 | public function info() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Generate connection token. |
||
| 183 | * |
||
| 184 | * @param string $userId |
||
| 185 | * @param int $exp |
||
| 186 | * @param array $info |
||
| 187 | * @return string |
||
| 188 | */ |
||
| 189 | public function generateConnectionToken(string $userId = '', int $exp = 0, array $info = []) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Generate private channel token. |
||
| 211 | * |
||
| 212 | * @param string $client |
||
| 213 | * @param string $channel |
||
| 214 | * @param int $exp |
||
| 215 | * @param array $info |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function generatePrivateChannelToken(string $client, string $channel, int $exp = 0, array $info = []) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Get secret key. |
||
| 240 | * |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | protected function getSecret() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Send message to centrifugo server. |
||
| 250 | * |
||
| 251 | * @param string $method |
||
| 252 | * @param array $params |
||
| 253 | * @return mixed |
||
| 254 | */ |
||
| 255 | protected function send($method, array $params = []) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Prepare URL to send the http request. |
||
| 297 | * |
||
| 298 | * @return string |
||
| 299 | */ |
||
| 300 | protected function prepareUrl() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Safely encode string in base64. |
||
| 314 | * @param string $input |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | private function urlsafeB64Encode($input) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Sign message with secret key. |
||
| 324 | * @param string $msg |
||
| 325 | * @param string $key |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | private function sign($msg, $key) |
||
| 332 | } |
||
| 333 |