diff --git a/src/ClientProviders/ConfigClientProvider.php b/src/ClientProviders/ConfigClientProvider.php index 90241fc..26074a9 100644 --- a/src/ClientProviders/ConfigClientProvider.php +++ b/src/ClientProviders/ConfigClientProvider.php @@ -33,8 +33,6 @@ class ConfigClientProvider implements ClientProvider return $this->instanciate($clientAttributes); } - - protected function allClients(): Collection { return collect(config('websockets.clients')); diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 43e7226..ac112be 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -30,8 +30,7 @@ class StartWebSocketServer extends Command app()->singleton(MessageLogger::class, function() { return (new MessageLogger($this->output)) ->enable(config('app.debug')) - //TODO: use real option - ->verbose($this->hasOption('vvv')); + ->verbose($this->output->isVerbose()); }); return $this; @@ -42,8 +41,7 @@ class StartWebSocketServer extends Command app()->bind(ConnectionLogger::class, function() { return (new ConnectionLogger($this->output)) ->enable(config('app.debug')) - //TODO: use real option - ->verbose($this->hasOption('vvv')); + ->verbose($this->output->isVerbose()); }); return $this; diff --git a/src/Exceptions/InvalidClient.php b/src/Exceptions/InvalidClient.php index d81260d..d76c8ef 100644 --- a/src/Exceptions/InvalidClient.php +++ b/src/Exceptions/InvalidClient.php @@ -2,7 +2,6 @@ namespace BeyondCode\LaravelWebSockets\Exceptions; - use Exception; class InvalidClient extends Exception @@ -19,6 +18,6 @@ class InvalidClient extends Exception public static function valueIsRequired($name, int $appId) { - return new static("{$name} is required but was empty for app id {$appId}"); + return new static("{$name} is required but was empty for app id `{$appId}`."); } } \ No newline at end of file diff --git a/src/Http/Controllers/SendMessage.php b/src/Http/Controllers/SendMessage.php index 9dcbad6..8b4c7df 100644 --- a/src/Http/Controllers/SendMessage.php +++ b/src/Http/Controllers/SendMessage.php @@ -18,6 +18,10 @@ class SendMessage ); return (new PusherBroadcaster($pusher)) - ->broadcast([$request->channel], $request->event, json_decode($request->data, true)); + ->broadcast( + [$request->channel], + $request->event, + json_decode($request->data, true) + ); } -} \ No newline at end of file +} diff --git a/src/Http/Controllers/ShowDashboard.php b/src/Http/Controllers/ShowDashboard.php index 2379467..b472020 100644 --- a/src/Http/Controllers/ShowDashboard.php +++ b/src/Http/Controllers/ShowDashboard.php @@ -10,7 +10,7 @@ class ShowDashboard public function __invoke(Request $request, ClientProvider $clients) { return view('websockets::dashboard', [ - 'clients' => $clients->all() + 'clients' => $clients->all(), ]); } } \ No newline at end of file diff --git a/src/LaravelEcho/Http/Controllers/EchoController.php b/src/LaravelEcho/Http/Controllers/EchoController.php index 4e5095b..f2606d5 100644 --- a/src/LaravelEcho/Http/Controllers/EchoController.php +++ b/src/LaravelEcho/Http/Controllers/EchoController.php @@ -40,8 +40,9 @@ abstract class EchoController implements HttpServerInterface $laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest)); - $this->verifyAppId($laravelRequest->appId); - $this->verifySignature($laravelRequest); + $this + ->ensureValidAppId($laravelRequest->appId) + ->ensureValidSignature($laravelRequest); $response = $this($laravelRequest); @@ -66,21 +67,21 @@ abstract class EchoController implements HttpServerInterface 'error' => $exception->getMessage() ])); - $connection->send(gPsr\str($response)); + $connection->send(Psr\str($response)); $connection->close(); } } - public function verifyAppId(string $appId) + public function ensureValidAppId(string $appId) { - if ($client = Client::findByAppId($appId)) { - return; + if (! $client = Client::findByAppId($appId)) { + throw new HttpException(401, "Unknown app id `{$appId}` provided."); } - throw new HttpException(401, "Unknown app id `{$appId}` provided."); + return true; } - protected function verifySignature(Request $request) + protected function ensureValidSignature(Request $request) { $bodyMd5 = md5($request->getContent()); @@ -96,6 +97,8 @@ abstract class EchoController implements HttpServerInterface if ($authSignature !== $request->get('auth_signature')) { throw new HttpException(401, 'Invalid auth signature provided.'); } + + return $this; } abstract public function __invoke(Request $request); diff --git a/src/LaravelEcho/Http/Controllers/TriggerEvent.php b/src/LaravelEcho/Http/Controllers/TriggerEvent.php index de0a016..7630ee1 100644 --- a/src/LaravelEcho/Http/Controllers/TriggerEvent.php +++ b/src/LaravelEcho/Http/Controllers/TriggerEvent.php @@ -9,10 +9,15 @@ class TriggerEvent extends EchoController { public function __invoke(Request $request) { - $this->verifySignature($request); + $this->ensureValidSignature($request); foreach ($request->json()->get('channels', []) as $channelId) { - Dashboard::apiMessage($request->appId, $channelId, $request->json()->get('name'), $request->json()->get('data')); + Dashboard::apiMessage( + $request->appId, + $channelId, + $request->json()->get('name'), + $request->json()->get('data') + ); $channel = $this->channelManager->find($request->appId, $channelId);