1 | <?php |
||
12 | class RedisStatisticsLogger implements StatisticsLogger |
||
13 | { |
||
14 | /** |
||
15 | * The Channel manager. |
||
16 | * |
||
17 | * @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager |
||
18 | */ |
||
19 | protected $channelManager; |
||
20 | |||
21 | /** |
||
22 | * The statistics driver instance. |
||
23 | * |
||
24 | * @var \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver |
||
25 | */ |
||
26 | protected $driver; |
||
27 | |||
28 | /** |
||
29 | * The replicator client. |
||
30 | * |
||
31 | * @var ReplicationInterface |
||
32 | */ |
||
33 | protected $replicator; |
||
34 | |||
35 | /** |
||
36 | * The Redis manager instance. |
||
37 | * |
||
38 | * @var \Illuminate\Redis\RedisManager |
||
39 | */ |
||
40 | protected $redis; |
||
41 | |||
42 | /** |
||
43 | * Initialize the logger. |
||
44 | * |
||
45 | * @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager |
||
46 | * @param \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver $driver |
||
47 | * @return void |
||
|
|||
48 | */ |
||
49 | public function __construct(ChannelManager $channelManager, StatisticsDriver $driver) |
||
59 | |||
60 | /** |
||
61 | * Handle the incoming websocket message. |
||
62 | * |
||
63 | * @param mixed $appId |
||
64 | * @return void |
||
65 | */ |
||
66 | public function webSocketMessage($appId) |
||
71 | |||
72 | /** |
||
73 | * Handle the incoming API message. |
||
74 | * |
||
75 | * @param mixed $appId |
||
76 | * @return void |
||
77 | */ |
||
78 | public function apiMessage($appId) |
||
83 | |||
84 | /** |
||
85 | * Handle the new conection. |
||
86 | * |
||
87 | * @param mixed $appId |
||
88 | * @return void |
||
89 | */ |
||
90 | public function connection($appId) |
||
117 | |||
118 | /** |
||
119 | * Handle disconnections. |
||
120 | * |
||
121 | * @param mixed $appId |
||
122 | * @return void |
||
123 | */ |
||
124 | public function disconnection($appId) |
||
151 | |||
152 | /** |
||
153 | * Save all the stored statistics. |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | public function save() |
||
200 | |||
201 | /** |
||
202 | * Ensure the app id is stored in the Redis database. |
||
203 | * |
||
204 | * @param mixed $appId |
||
205 | * @return \Illuminate\Redis\RedisManager |
||
206 | */ |
||
207 | protected function ensureAppIsSet($appId) |
||
215 | |||
216 | /** |
||
217 | * Reset the statistics to a specific connection count. |
||
218 | * |
||
219 | * @param mixed $appId |
||
220 | * @param int $currentConnectionCount |
||
221 | * @return void |
||
222 | */ |
||
223 | public function resetStatistics($appId, int $currentConnectionCount) |
||
241 | |||
242 | /** |
||
243 | * Remove all app traces from the database if no connections have been set |
||
244 | * in the meanwhile since last save. |
||
245 | * |
||
246 | * @param mixed $appId |
||
247 | * @return void |
||
248 | */ |
||
249 | public function resetAppTraces($appId) |
||
271 | |||
272 | /** |
||
273 | * Get the Redis hash name for the app. |
||
274 | * |
||
275 | * @param mixed $appId |
||
276 | * @return string |
||
277 | */ |
||
278 | protected function getHash($appId): string |
||
282 | |||
283 | /** |
||
284 | * Get a new RedisLock instance to avoid race conditions. |
||
285 | * |
||
286 | * @return \Illuminate\Cache\CacheLock |
||
287 | */ |
||
288 | protected function lock() |
||
292 | |||
293 | /** |
||
294 | * Create a new record using the Statistic Driver. |
||
295 | * |
||
296 | * @param array $statistic |
||
297 | * @param mixed $appId |
||
298 | * @return void |
||
299 | */ |
||
300 | protected function createRecord(array $statistic, $appId): void |
||
309 | } |
||
310 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.