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 Redis manager instance. |
||
30 | * |
||
31 | * @var \Illuminate\Redis\RedisManager |
||
32 | */ |
||
33 | protected $redis; |
||
34 | |||
35 | /** |
||
36 | * Initialize the logger. |
||
37 | * |
||
38 | * @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager |
||
39 | * @param \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver $driver |
||
40 | * @return void |
||
|
|||
41 | */ |
||
42 | public function __construct(ChannelManager $channelManager, StatisticsDriver $driver) |
||
52 | |||
53 | /** |
||
54 | * Handle the incoming websocket message. |
||
55 | * |
||
56 | * @param mixed $appId |
||
57 | * @return void |
||
58 | */ |
||
59 | public function webSocketMessage($appId) |
||
64 | |||
65 | /** |
||
66 | * Handle the incoming API message. |
||
67 | * |
||
68 | * @param mixed $appId |
||
69 | * @return void |
||
70 | */ |
||
71 | public function apiMessage($appId) |
||
76 | |||
77 | /** |
||
78 | * Handle the new conection. |
||
79 | * |
||
80 | * @param mixed $appId |
||
81 | * @return void |
||
82 | */ |
||
83 | public function connection($appId) |
||
110 | |||
111 | /** |
||
112 | * Handle disconnections. |
||
113 | * |
||
114 | * @param mixed $appId |
||
115 | * @return void |
||
116 | */ |
||
117 | public function disconnection($appId) |
||
144 | |||
145 | /** |
||
146 | * Save all the stored statistics. |
||
147 | * |
||
148 | * @return void |
||
149 | */ |
||
150 | public function save() |
||
193 | |||
194 | /** |
||
195 | * Ensure the app id is stored in the Redis database. |
||
196 | * |
||
197 | * @param mixed $appId |
||
198 | * @return \Illuminate\Redis\RedisManager |
||
199 | */ |
||
200 | protected function ensureAppIsSet($appId) |
||
208 | |||
209 | /** |
||
210 | * Reset the statistics to a specific connection count. |
||
211 | * |
||
212 | * @param mixed $appId |
||
213 | * @param int $currentConnectionCount |
||
214 | * @return void |
||
215 | */ |
||
216 | public function resetStatistics($appId, int $currentConnectionCount) |
||
234 | |||
235 | /** |
||
236 | * Remove all app traces from the database if no connections have been set |
||
237 | * in the meanwhile since last save. |
||
238 | * |
||
239 | * @param mixed $appId |
||
240 | * @return void |
||
241 | */ |
||
242 | public function resetAppTraces($appId) |
||
264 | |||
265 | /** |
||
266 | * Get the Redis hash name for the app. |
||
267 | * |
||
268 | * @param mixed $appId |
||
269 | * @return string |
||
270 | */ |
||
271 | protected function getHash($appId): string |
||
275 | |||
276 | /** |
||
277 | * Get a new RedisLock instance to avoid race conditions. |
||
278 | * |
||
279 | * @return \Illuminate\Cache\CacheLock |
||
280 | */ |
||
281 | protected function lock() |
||
285 | |||
286 | /** |
||
287 | * Create a new record using the Statistic Driver. |
||
288 | * |
||
289 | * @param array $statistic |
||
290 | * @param mixed $appId |
||
291 | * @return void |
||
292 | */ |
||
293 | protected function createRecord(array $statistic, $appId): void |
||
302 | } |
||
303 |
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.