1 | <?php |
||
10 | class MemoryStatisticsLogger implements StatisticsLogger |
||
11 | { |
||
12 | /** |
||
13 | * The list of stored statistics. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $statistics = []; |
||
18 | |||
19 | /** |
||
20 | * The Channel manager. |
||
21 | * |
||
22 | * @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager |
||
23 | */ |
||
24 | protected $channelManager; |
||
25 | |||
26 | /** |
||
27 | * The statistics driver instance. |
||
28 | * |
||
29 | * @var \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver |
||
30 | */ |
||
31 | protected $driver; |
||
32 | |||
33 | /** |
||
34 | * Initialize the logger. |
||
35 | * |
||
36 | * @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager |
||
37 | * @param \BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver $driver |
||
38 | * @return void |
||
|
|||
39 | */ |
||
40 | public function __construct(ChannelManager $channelManager, StatisticsDriver $driver) |
||
45 | |||
46 | /** |
||
47 | * Handle the incoming websocket message. |
||
48 | * |
||
49 | * @param mixed $appId |
||
50 | * @return void |
||
51 | */ |
||
52 | public function webSocketMessage($appId) |
||
57 | |||
58 | /** |
||
59 | * Handle the incoming API message. |
||
60 | * |
||
61 | * @param mixed $appId |
||
62 | * @return void |
||
63 | */ |
||
64 | public function apiMessage($appId) |
||
69 | |||
70 | /** |
||
71 | * Handle the new conection. |
||
72 | * |
||
73 | * @param mixed $appId |
||
74 | * @return void |
||
75 | */ |
||
76 | public function connection($appId) |
||
81 | |||
82 | /** |
||
83 | * Handle disconnections. |
||
84 | * |
||
85 | * @param mixed $appId |
||
86 | * @return void |
||
87 | */ |
||
88 | public function disconnection($appId) |
||
93 | |||
94 | /** |
||
95 | * Save all the stored statistics. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function save() |
||
113 | |||
114 | /** |
||
115 | * Find or create a defined statistic for an app. |
||
116 | * |
||
117 | * @param mixed $appId |
||
118 | * @return Statistic |
||
119 | */ |
||
120 | protected function findOrMakeStatisticForAppId($appId): Statistic |
||
128 | |||
129 | /** |
||
130 | * Get the saved statistics. |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | public function getStatistics(): array |
||
138 | |||
139 | /** |
||
140 | * Create a new record using the Statistic Driver. |
||
141 | * |
||
142 | * @param Statistic $statistic |
||
143 | * @param mixed $appId |
||
144 | * @return void |
||
145 | */ |
||
146 | public function createRecord(Statistic $statistic, $appId) |
||
150 | } |
||
151 |
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.