@@ -26,7 +26,7 @@ |
||
26 | 26 | // and the values are on odd indexes. This way, we know which |
27 | 27 | // ones are keys and which ones are values and their get combined |
28 | 28 | // later to form the key => value array. |
29 | - [$keys, $values] = collect($list)->partition(function ($value, $key) { |
|
29 | + [$keys, $values] = collect($list)->partition(function($value, $key) { |
|
30 | 30 | return $key % 2 === 0; |
31 | 31 | }); |
32 | 32 |
@@ -23,27 +23,27 @@ discard block |
||
23 | 23 | if ($request->has('info')) { |
24 | 24 | $attributes = explode(',', trim($request->info)); |
25 | 25 | |
26 | - if (in_array('user_count', $attributes) && ! Str::startsWith($request->filter_by_prefix, 'presence-')) { |
|
26 | + if (in_array('user_count', $attributes) && !Str::startsWith($request->filter_by_prefix, 'presence-')) { |
|
27 | 27 | throw new HttpException(400, 'Request must be limited to presence channels in order to fetch user_count'); |
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
31 | 31 | return $this->channelManager |
32 | 32 | ->getGlobalChannels($request->appId) |
33 | - ->then(function ($channels) use ($request, $attributes) { |
|
34 | - $channels = collect($channels)->keyBy(function ($channel) { |
|
33 | + ->then(function($channels) use ($request, $attributes) { |
|
34 | + $channels = collect($channels)->keyBy(function($channel) { |
|
35 | 35 | return $channel instanceof Channel |
36 | 36 | ? $channel->getName() |
37 | 37 | : $channel; |
38 | 38 | }); |
39 | 39 | |
40 | 40 | if ($request->has('filter_by_prefix')) { |
41 | - $channels = $channels->filter(function ($channel, $channelName) use ($request) { |
|
41 | + $channels = $channels->filter(function($channel, $channelName) use ($request) { |
|
42 | 42 | return Str::startsWith($channelName, $request->filter_by_prefix); |
43 | 43 | }); |
44 | 44 | } |
45 | 45 | |
46 | - $channelNames = $channels->map(function ($channel) { |
|
46 | + $channelNames = $channels->map(function($channel) { |
|
47 | 47 | return $channel instanceof Channel |
48 | 48 | ? $channel->getName() |
49 | 49 | : $channel; |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | |
52 | 52 | return $this->channelManager |
53 | 53 | ->getChannelsMembersCount($request->appId, $channelNames) |
54 | - ->then(function ($counts) use ($channels, $attributes) { |
|
55 | - $channels = $channels->map(function ($channel) use ($counts, $attributes) { |
|
54 | + ->then(function($counts) use ($channels, $attributes) { |
|
55 | + $channels = $channels->map(function($channel) use ($counts, $attributes) { |
|
56 | 56 | $info = new stdClass; |
57 | 57 | |
58 | 58 | $channelName = $channel instanceof Channel |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | return $info; |
67 | - })->sortBy(function ($content, $name) { |
|
67 | + })->sortBy(function($content, $name) { |
|
68 | 68 | return $name; |
69 | 69 | })->all(); |
70 | 70 |
@@ -16,14 +16,14 @@ |
||
16 | 16 | */ |
17 | 17 | public function __invoke(Request $request) |
18 | 18 | { |
19 | - if (! Str::startsWith($request->channelName, 'presence-')) { |
|
19 | + if (!Str::startsWith($request->channelName, 'presence-')) { |
|
20 | 20 | return new HttpException(400, "Invalid presence channel `{$request->channelName}`"); |
21 | 21 | } |
22 | 22 | |
23 | 23 | return $this->channelManager |
24 | 24 | ->getChannelMembers($request->appId, $request->channelName) |
25 | - ->then(function ($members) { |
|
26 | - $users = collect($members)->map(function ($user) { |
|
25 | + ->then(function($members) { |
|
26 | + $users = collect($members)->map(function($user) { |
|
27 | 27 | return ['id' => $user->user_id]; |
28 | 28 | })->values()->toArray(); |
29 | 29 |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | $this->requestBuffer = (string) $request->getBody(); |
87 | 87 | |
88 | - if (! $this->verifyContentLength()) { |
|
88 | + if (!$this->verifyContentLength()) { |
|
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | { |
104 | 104 | $this->requestBuffer .= $msg; |
105 | 105 | |
106 | - if (! $this->verifyContentLength()) { |
|
106 | + if (!$this->verifyContentLength()) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function onError(ConnectionInterface $connection, Exception $exception) |
132 | 132 | { |
133 | - if (! $exception instanceof HttpException) { |
|
133 | + if (!$exception instanceof HttpException) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | protected function findContentLength(array $headers): int |
153 | 153 | { |
154 | - return Collection::make($headers)->first(function ($values, $header) { |
|
154 | + return Collection::make($headers)->first(function($values, $header) { |
|
155 | 155 | return strtolower($header) === 'content-length'; |
156 | 156 | })[0] ?? 0; |
157 | 157 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | // Allow for async IO in the controller action |
194 | 194 | if ($response instanceof PromiseInterface) { |
195 | - $response->then(function ($response) use ($connection) { |
|
195 | + $response->then(function($response) use ($connection) { |
|
196 | 196 | $this->sendAndClose($connection, $response); |
197 | 197 | }); |
198 | 198 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function ensureValidAppId($appId) |
230 | 230 | { |
231 | - if (! $appId || ! $this->app = App::findById($appId)) { |
|
231 | + if (!$appId || !$this->app = App::findById($appId)) { |
|
232 | 232 | throw new HttpException(401, "Unknown app id `{$appId}` provided."); |
233 | 233 | } |
234 | 234 |
@@ -26,13 +26,13 @@ |
||
26 | 26 | |
27 | 27 | return $this->channelManager |
28 | 28 | ->getGlobalConnectionsCount($request->appId, $request->channelName) |
29 | - ->then(function ($connectionsCount) use ($request) { |
|
29 | + ->then(function($connectionsCount) use ($request) { |
|
30 | 30 | // For the presence channels, we need a slightly different response |
31 | 31 | // that need an additional call. |
32 | 32 | if (Str::startsWith($request->channelName, 'presence-')) { |
33 | 33 | return $this->channelManager |
34 | 34 | ->getChannelsMembersCount($request->appId, [$request->channelName]) |
35 | - ->then(function ($channelMembers) use ($connectionsCount, $request) { |
|
35 | + ->then(function($channelMembers) use ($connectionsCount, $request) { |
|
36 | 36 | return [ |
37 | 37 | 'occupied' => $connectionsCount > 0, |
38 | 38 | 'subscription_count' => $connectionsCount, |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $this->channelManager->getStatsRedisHash($appId, null), |
86 | 86 | 'current_connections_count', 1 |
87 | 87 | ) |
88 | - ->then(function ($currentConnectionsCount) use ($appId) { |
|
88 | + ->then(function($currentConnectionsCount) use ($appId) { |
|
89 | 89 | // Get the peak connections count from Redis. |
90 | 90 | $this->channelManager |
91 | 91 | ->getPublishClient() |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $this->channelManager->getStatsRedisHash($appId, null), |
94 | 94 | 'peak_connections_count' |
95 | 95 | ) |
96 | - ->then(function ($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) { |
|
96 | + ->then(function($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) { |
|
97 | 97 | // Extract the greatest number between the current peak connection count |
98 | 98 | // and the current connection number. |
99 | 99 | $peakConnectionsCount = is_null($currentPeakConnectionCount) |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | // Decrement the current connections count by 1. |
123 | 123 | $this->ensureAppIsInSet($appId) |
124 | 124 | ->hincrby($this->channelManager->getStatsRedisHash($appId, null), 'current_connections_count', -1) |
125 | - ->then(function ($currentConnectionsCount) use ($appId) { |
|
125 | + ->then(function($currentConnectionsCount) use ($appId) { |
|
126 | 126 | // Get the peak connections count from Redis. |
127 | 127 | $this->channelManager |
128 | 128 | ->getPublishClient() |
129 | 129 | ->hget($this->channelManager->getStatsRedisHash($appId, null), 'peak_connections_count') |
130 | - ->then(function ($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) { |
|
130 | + ->then(function($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) { |
|
131 | 131 | // Extract the greatest number between the current peak connection count |
132 | 132 | // and the current connection number. |
133 | 133 | $peakConnectionsCount = is_null($currentPeakConnectionCount) |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function save() |
154 | 154 | { |
155 | - $this->lock()->get(function () { |
|
155 | + $this->lock()->get(function() { |
|
156 | 156 | $this->channelManager |
157 | 157 | ->getPublishClient() |
158 | 158 | ->smembers(static::$redisSetName) |
159 | - ->then(function ($members) { |
|
159 | + ->then(function($members) { |
|
160 | 160 | foreach ($members as $appId) { |
161 | 161 | $this->channelManager |
162 | 162 | ->getPublishClient() |
163 | 163 | ->hgetall($this->channelManager->getStatsRedisHash($appId, null)) |
164 | - ->then(function ($list) use ($appId) { |
|
165 | - if (! $list) { |
|
164 | + ->then(function($list) use ($appId) { |
|
165 | + if (!$list) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | $this->channelManager |
180 | 180 | ->getGlobalConnectionsCount($appId) |
181 | - ->then(function ($currentConnectionsCount) use ($appId) { |
|
181 | + ->then(function($currentConnectionsCount) use ($appId) { |
|
182 | 182 | $currentConnectionsCount === 0 || is_null($currentConnectionsCount) |
183 | 183 | ? $this->resetAppTraces($appId) |
184 | 184 | : $this->resetStatistics($appId, $currentConnectionsCount); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function flush() |
198 | 198 | { |
199 | - $this->getStatistics()->then(function ($statistics) { |
|
199 | + $this->getStatistics()->then(function($statistics) { |
|
200 | 200 | foreach ($statistics as $appId => $statistic) { |
201 | 201 | $this->resetAppTraces($appId); |
202 | 202 | } |
@@ -213,14 +213,14 @@ discard block |
||
213 | 213 | return $this->channelManager |
214 | 214 | ->getPublishClient() |
215 | 215 | ->smembers(static::$redisSetName) |
216 | - ->then(function ($members) { |
|
216 | + ->then(function($members) { |
|
217 | 217 | $appsWithStatistics = []; |
218 | 218 | |
219 | 219 | foreach ($members as $appId) { |
220 | 220 | $this->channelManager |
221 | 221 | ->getPublishClient() |
222 | 222 | ->hgetall($this->channelManager->getStatsRedisHash($appId, null)) |
223 | - ->then(function ($list) use ($appId, &$appsWithStatistics) { |
|
223 | + ->then(function($list) use ($appId, &$appsWithStatistics) { |
|
224 | 224 | $appsWithStatistics[$appId] = $this->arrayToStatisticInstance( |
225 | 225 | $appId, Helpers::redisListToArray($list) |
226 | 226 | ); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | return $this->channelManager |
243 | 243 | ->getPublishClient() |
244 | 244 | ->hgetall($this->channelManager->getStatsRedisHash($appId, null)) |
245 | - ->then(function ($list) use ($appId) { |
|
245 | + ->then(function($list) use ($appId) { |
|
246 | 246 | return $this->arrayToStatisticInstance( |
247 | 247 | $appId, Helpers::redisListToArray($list) |
248 | 248 | ); |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function save() |
92 | 92 | { |
93 | - $this->getStatistics()->then(function ($statistics) { |
|
93 | + $this->getStatistics()->then(function($statistics) { |
|
94 | 94 | foreach ($statistics as $appId => $statistic) { |
95 | - if (! $statistic->isEnabled()) { |
|
95 | + if (!$statistic->isEnabled()) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | $this->channelManager |
108 | 108 | ->getGlobalConnectionsCount($appId) |
109 | - ->then(function ($connections) use ($statistic) { |
|
109 | + ->then(function($connections) use ($statistic) { |
|
110 | 110 | $statistic->reset( |
111 | 111 | is_null($connections) ? 0 : $connections |
112 | 112 | ); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function findOrMake($appId): Statistic |
170 | 170 | { |
171 | - if (! isset($this->statistics[$appId])) { |
|
171 | + if (!isset($this->statistics[$appId])) { |
|
172 | 172 | $this->statistics[$appId] = Statistic::new($appId); |
173 | 173 | } |
174 | 174 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function delete(Carbon $moment, $appId = null): int |
41 | 41 | { |
42 | 42 | return static::$model::where('created_at', '<', $moment->toDateTimeString()) |
43 | - ->when(! is_null($appId), function ($query) use ($appId) { |
|
43 | + ->when(!is_null($appId), function($query) use ($appId) { |
|
44 | 44 | return $query->whereAppId($appId); |
45 | 45 | }) |
46 | 46 | ->delete(); |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | public function getRawRecords(callable $processQuery = null) |
56 | 56 | { |
57 | 57 | return static::$model::query() |
58 | - ->when(! is_null($processQuery), function ($query) use ($processQuery) { |
|
58 | + ->when(!is_null($processQuery), function($query) use ($processQuery) { |
|
59 | 59 | return call_user_func($processQuery, $query); |
60 | - }, function ($query) { |
|
60 | + }, function($query) { |
|
61 | 61 | return $query->latest()->limit(120); |
62 | 62 | })->get(); |
63 | 63 | } |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | public function getRecords(callable $processQuery = null, callable $processCollection = null): array |
73 | 73 | { |
74 | 74 | return $this->getRawRecords($processQuery) |
75 | - ->when(! is_null($processCollection), function ($collection) use ($processCollection) { |
|
75 | + ->when(!is_null($processCollection), function($collection) use ($processCollection) { |
|
76 | 76 | return call_user_func($processCollection, $collection); |
77 | 77 | }) |
78 | - ->map(function (Model $statistic) { |
|
78 | + ->map(function(Model $statistic) { |
|
79 | 79 | return $this->statisticToArray($statistic); |
80 | 80 | }) |
81 | 81 | ->toArray(); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function configureManagers() |
108 | 108 | { |
109 | - $this->laravel->singleton(ChannelManager::class, function ($app) { |
|
109 | + $this->laravel->singleton(ChannelManager::class, function($app) { |
|
110 | 110 | $config = $app['config']['websockets']; |
111 | 111 | $mode = $config['replication']['mode'] ?? 'local'; |
112 | 112 | |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | */ |
125 | 125 | protected function configureStatistics() |
126 | 126 | { |
127 | - if (! $this->option('disable-statistics')) { |
|
127 | + if (!$this->option('disable-statistics')) { |
|
128 | 128 | $intervalInSeconds = $this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds', 3600); |
129 | 129 | |
130 | - $this->loop->addPeriodicTimer($intervalInSeconds, function () { |
|
130 | + $this->loop->addPeriodicTimer($intervalInSeconds, function() { |
|
131 | 131 | $this->line('Saving statistics...'); |
132 | 132 | |
133 | 133 | StatisticsCollectorFacade::save(); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | { |
145 | 145 | $this->lastRestart = $this->getLastRestart(); |
146 | 146 | |
147 | - $this->loop->addPeriodicTimer(10, function () { |
|
147 | + $this->loop->addPeriodicTimer(10, function() { |
|
148 | 148 | if ($this->getLastRestart() !== $this->lastRestart) { |
149 | 149 | $this->triggerSoftShutdown(); |
150 | 150 | } |
@@ -173,17 +173,17 @@ discard block |
||
173 | 173 | // to receive new connections, close the current connections, |
174 | 174 | // then stopping the loop. |
175 | 175 | |
176 | - if (! extension_loaded('pcntl')) { |
|
176 | + if (!extension_loaded('pcntl')) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - $this->loop->addSignal(SIGTERM, function () { |
|
180 | + $this->loop->addSignal(SIGTERM, function() { |
|
181 | 181 | $this->line('Closing existing connections...'); |
182 | 182 | |
183 | 183 | $this->triggerSoftShutdown(); |
184 | 184 | }); |
185 | 185 | |
186 | - $this->loop->addSignal(SIGINT, function () { |
|
186 | + $this->loop->addSignal(SIGINT, function() { |
|
187 | 187 | $this->line('Closing existing connections...'); |
188 | 188 | |
189 | 189 | $this->triggerSoftShutdown(); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function configurePongTracker() |
200 | 200 | { |
201 | - $this->loop->addPeriodicTimer(10, function () { |
|
201 | + $this->loop->addPeriodicTimer(10, function() { |
|
202 | 202 | $this->laravel |
203 | 203 | ->make(ChannelManager::class) |
204 | 204 | ->removeObsoleteConnections(); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function configureHttpLogger() |
214 | 214 | { |
215 | - $this->laravel->singleton(HttpLogger::class, function ($app) { |
|
215 | + $this->laravel->singleton(HttpLogger::class, function($app) { |
|
216 | 216 | return (new HttpLogger($this->output)) |
217 | 217 | ->enable($this->option('debug') ?: ($app['config']['app']['debug'] ?? false)) |
218 | 218 | ->verbose($this->output->isVerbose()); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | protected function configureMessageLogger() |
228 | 228 | { |
229 | - $this->laravel->singleton(WebSocketsLogger::class, function ($app) { |
|
229 | + $this->laravel->singleton(WebSocketsLogger::class, function($app) { |
|
230 | 230 | return (new WebSocketsLogger($this->output)) |
231 | 231 | ->enable($this->option('debug') ?: ($app['config']['app']['debug'] ?? false)) |
232 | 232 | ->verbose($this->output->isVerbose()); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function configureConnectionLogger() |
242 | 242 | { |
243 | - $this->laravel->bind(ConnectionLogger::class, function ($app) { |
|
243 | + $this->laravel->bind(ConnectionLogger::class, function($app) { |
|
244 | 244 | return (new ConnectionLogger($this->output)) |
245 | 245 | ->enable($app['config']['app']['debug'] ?? false) |
246 | 246 | ->verbose($this->output->isVerbose()); |
@@ -310,12 +310,12 @@ discard block |
||
310 | 310 | // Get all local connections and close them. They will |
311 | 311 | // be automatically be unsubscribed from all channels. |
312 | 312 | $channelManager->getLocalConnections() |
313 | - ->then(function ($connections) { |
|
313 | + ->then(function($connections) { |
|
314 | 314 | foreach ($connections as $connection) { |
315 | 315 | $connection->close(); |
316 | 316 | } |
317 | 317 | }) |
318 | - ->then(function () { |
|
318 | + ->then(function() { |
|
319 | 319 | $this->loop->stop(); |
320 | 320 | }); |
321 | 321 | } |