diff --git a/src/Centrifugo.php b/src/Centrifugo.php index d48cc186e80ad6285925de0b817e84044163526b..0214baef9680ee44880ca1a07f4cc69c411a5256 100644 --- a/src/Centrifugo.php +++ b/src/Centrifugo.php @@ -42,7 +42,7 @@ class Centrifugo implements CentrifugoInterface * * @return array */ - protected function initConfiguration(array $config) : array + protected function initConfiguration(array $config): array { $defaults = [ 'url' => 'http://localhost:8000', @@ -70,7 +70,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function publish(string $channel, array $data, bool $skipHistory = false) : array + public function publish(string $channel, array $data, bool $skipHistory = false): array { return $this->send('publish', [ 'channel' => $channel, @@ -88,7 +88,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function broadcast(array $channels, array $data, bool $skipHistory = false) : array + public function broadcast(array $channels, array $data, bool $skipHistory = false): array { $params = [ 'channels' => $channels, @@ -106,7 +106,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function presence(string $channel) : array + public function presence(string $channel): array { return $this->send('presence', ['channel' => $channel]); } @@ -118,7 +118,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function presenceStats(string $channel) : array + public function presenceStats(string $channel): array { return $this->send('presence_stats', ['channel' => $channel]); } @@ -133,7 +133,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function history(string $channel, $limit = 0, array $since = [], bool $reverse = false) : array + public function history(string $channel, $limit = 0, array $since = [], bool $reverse = false): array { $params = [ 'channel' => $channel, @@ -154,7 +154,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function historyRemove(string $channel) : array + public function historyRemove(string $channel): array { return $this->send('history_remove', [ 'channel' => $channel, @@ -170,7 +170,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function subscribe($channel, $user, $client = '') : array + public function subscribe($channel, $user, $client = ''): array { return $this->send('subscribe', [ 'channel' => $channel, @@ -188,7 +188,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function unsubscribe(string $channel, string $user, string $client = '') : array + public function unsubscribe(string $channel, string $user, string $client = ''): array { return $this->send('unsubscribe', [ 'channel' => $channel, @@ -204,7 +204,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function disconnect(string $user_id, string $client = '') : array + public function disconnect(string $user_id, string $client = ''): array { return $this->send('disconnect', [ 'user' => $user_id, @@ -219,7 +219,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function channels(string $pattern = '') : array + public function channels(string $pattern = ''): array { return $this->send('channels', ['pattern' => $pattern]); } @@ -229,7 +229,7 @@ class Centrifugo implements CentrifugoInterface * * @return mixed */ - public function info() : array + public function info(): array { return $this->send('info'); } @@ -323,28 +323,29 @@ class Centrifugo implements CentrifugoInterface * @param string $method * @param array $params * - * @return mixed * @throws GuzzleException + * + * @return mixed */ - protected function send(string $method, array $params = []) : array + protected function send(string $method, array $params = []): array { $json = json_encode(['method' => $method, 'params' => $params]); $url = $this->prepareUrl(); - $config =[ - 'base_uri' => $url, + $config = [ + 'base_uri' => $url, 'headers' => [ 'Content-type' => 'application/json', - 'X-API-Key' => $this->getApiKey(), + 'X-API-Key' => $this->getApiKey(), ], 'json' => $params, 'http_errors' => true, - 'verify' => $this->config['verify'], - 'ssl_key' => $this->config['ssl_key'] + 'verify' => $this->config['verify'], + 'ssl_key' => $this->config['ssl_key'], ]; - try { + try { $response = $this->httpClient->post($method, $config); $result = json_decode((string) $response->getBody(), true); diff --git a/src/CentrifugoServiceProvider.php b/src/CentrifugoServiceProvider.php index 55f7183feb3d961d4e8f0f4533fb01f8e374355c..bbc99f96f202e2f651edf6236b244f29513c2740 100644 --- a/src/CentrifugoServiceProvider.php +++ b/src/CentrifugoServiceProvider.php @@ -22,7 +22,6 @@ class CentrifugoServiceProvider extends ServiceProvider $this->commands(InstallCommand::class); } - $broadcastManager->extend('centrifugo', function ($app) { return new CentrifugoBroadcaster($app->make('centrifugo')); }); @@ -35,7 +34,6 @@ class CentrifugoServiceProvider extends ServiceProvider */ public function register(): void { - $this->app->singleton('centrifugo', function ($app) { $config = $app->make('config')->get('broadcasting.connections.centrifugo'); $http = new HttpClient(); diff --git a/src/Commands/InstallCommand.php b/src/Commands/InstallCommand.php index 19095c962a5531cc280c7bb8daaf04e43472472e..d62a88d8f353ce7ae168f85e6e0c497d9f7f13ca 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/InstallCommand.php @@ -49,16 +49,15 @@ class InstallCommand extends Command } $contents = File::get($env); - $token_hmac_secret_key=Str::uuid()->toString(); - $api_key=Str::uuid()->toString(); - + $token_hmac_secret_key = Str::uuid()->toString(); + $api_key = Str::uuid()->toString(); $variables = Arr::where([ 'CENTRIFUGO_TOKEN_HMAC_SECRET_KEY' => "CENTRIFUGO_TOKEN_HMAC_SECRET_KEY={$token_hmac_secret_key}", - 'CENTRIFUGO_API_KEY' => "CENTRIFUGO_API_KEY={$api_key}", - 'CENTRIFUGO_URL' => 'CENTRIFUGO_URL="http://localhost:8000"' + 'CENTRIFUGO_API_KEY' => "CENTRIFUGO_API_KEY={$api_key}", + 'CENTRIFUGO_URL' => 'CENTRIFUGO_URL="http://localhost:8000"', ], function ($value, $key) use ($contents) { - return ! Str::contains($contents, PHP_EOL.$key); + return !Str::contains($contents, PHP_EOL.$key); }); $variables = trim(implode(PHP_EOL, $variables)); @@ -81,7 +80,7 @@ class InstallCommand extends Command return; $this->callSilently('vendor:publish', [ '--provider' => 'App\Providers\BroadcastServiceProvider', - '--tag' => 'centrifuge-config', + '--tag' => 'centrifuge-config', ]); } @@ -94,7 +93,6 @@ class InstallCommand extends Command return; } - File::replaceInFile( "'connections' => [\n", <<<'CONFIG' @@ -128,7 +126,7 @@ class InstallCommand extends Command $enable = confirm('Would you like to enable event broadcasting?', default: true); - if (! $enable) { + if (!$enable) { return; } @@ -158,8 +156,7 @@ class InstallCommand extends Command */ protected function updateBroadcastingDriver(): void { - - if ( File::missing($env = app()->environmentFile())) { + if (File::missing($env = app()->environmentFile())) { return; }