From edcf205dba465b9474127d9f0fb7586d986a68a6 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Wed, 27 Feb 2019 15:23:47 +0100 Subject: [PATCH 1/2] Apply fixes from StyleCI (#123) --- src/HttpApi/Controllers/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpApi/Controllers/Controller.php b/src/HttpApi/Controllers/Controller.php index 92315c2..17279bf 100644 --- a/src/HttpApi/Controllers/Controller.php +++ b/src/HttpApi/Controllers/Controller.php @@ -43,7 +43,7 @@ abstract class Controller implements HttpServerInterface $this->contentLength = $this->findContentLength($request->getHeaders()); - $this->requestBuffer = (string)$request->getBody(); + $this->requestBuffer = (string) $request->getBody(); $this->checkContentLength($connection); } From 3ec6c0ade32be70869abb2c9414f10df21ab4075 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Wed, 27 Feb 2019 09:27:21 -0500 Subject: [PATCH 2/2] Add support for Laravel 5.8 (#122) * Fix Laravel 5.8 compatibility * Use Arr:: and Str:: instead of global helpers * Remove testbench-core dependency, release was tagged --- composer.json | 12 ++++++------ src/HttpApi/Controllers/Controller.php | 3 ++- src/HttpApi/Controllers/FetchChannelsController.php | 3 ++- src/Statistics/Events/StatisticsUpdated.php | 3 ++- src/WebSockets/Channels/Channel.php | 3 ++- .../Channels/ChannelManagers/ArrayChannelManager.php | 12 +++++++----- .../Messages/PusherChannelProtocolMessage.php | 3 ++- src/WebSockets/Messages/PusherClientMessage.php | 3 ++- src/WebSockets/Messages/PusherMessageFactory.php | 3 ++- tests/ClientProviders/ConfigAppProviderTest.php | 2 +- tests/Commands/CleanStatisticsTest.php | 2 +- tests/TestCase.php | 2 +- 12 files changed, 30 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 7f1fda4..028678a 100644 --- a/composer.json +++ b/composer.json @@ -27,18 +27,18 @@ "cboden/ratchet": "^0.4.1", "clue/buzz-react": "^2.5", "guzzlehttp/psr7": "^1.5", - "illuminate/broadcasting": "5.7.*", - "illuminate/console": "5.7.*", - "illuminate/http": "5.7.*", - "illuminate/routing": "5.7.*", - "illuminate/support": "5.7.*", + "illuminate/broadcasting": "5.7.* || 5.8.*", + "illuminate/console": "5.7.* || 5.8.*", + "illuminate/http": "5.7.* || 5.8.*", + "illuminate/routing": "5.7.* || 5.8.*", + "illuminate/support": "5.7.* || 5.8.*", "pusher/pusher-php-server": "~3.0", "symfony/http-kernel": "~4.0", "symfony/psr-http-message-bridge": "^1.1" }, "require-dev": { "mockery/mockery": "^1.2", - "orchestra/testbench": "3.7.*", + "orchestra/testbench": "3.7.* || 3.8.*", "phpunit/phpunit": "^7.0" }, "autoload": { diff --git a/src/HttpApi/Controllers/Controller.php b/src/HttpApi/Controllers/Controller.php index 17279bf..bdad26a 100644 --- a/src/HttpApi/Controllers/Controller.php +++ b/src/HttpApi/Controllers/Controller.php @@ -4,6 +4,7 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; use Exception; use Pusher\Pusher; +use Illuminate\Support\Arr; use Illuminate\Http\Request; use GuzzleHttp\Psr7\Response; use Ratchet\ConnectionInterface; @@ -123,7 +124,7 @@ abstract class Controller implements HttpServerInterface * * The `appId`, `appKey` & `channelName` parameters are actually route paramaters and are never supplied by the client. */ - $params = array_except($request->query(), ['auth_signature', 'body_md5', 'appId', 'appKey', 'channelName']); + $params = Arr::except($request->query(), ['auth_signature', 'body_md5', 'appId', 'appKey', 'channelName']); if ($request->getContent() !== '') { $params['body_md5'] = md5($request->getContent()); diff --git a/src/HttpApi/Controllers/FetchChannelsController.php b/src/HttpApi/Controllers/FetchChannelsController.php index 22d8c1f..192a52c 100644 --- a/src/HttpApi/Controllers/FetchChannelsController.php +++ b/src/HttpApi/Controllers/FetchChannelsController.php @@ -2,6 +2,7 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; +use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Support\Collection; use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel; @@ -16,7 +17,7 @@ class FetchChannelsController extends Controller if ($request->has('filter_by_prefix')) { $channels = $channels->filter(function ($channel, $channelName) use ($request) { - return starts_with($channelName, $request->filter_by_prefix); + return Str::startsWith($channelName, $request->filter_by_prefix); }); } diff --git a/src/Statistics/Events/StatisticsUpdated.php b/src/Statistics/Events/StatisticsUpdated.php index b3ed0d9..6e2ac35 100644 --- a/src/Statistics/Events/StatisticsUpdated.php +++ b/src/Statistics/Events/StatisticsUpdated.php @@ -2,6 +2,7 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Events; +use Illuminate\Support\Str; use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; @@ -33,7 +34,7 @@ class StatisticsUpdated implements ShouldBroadcast public function broadcastOn() { - $channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX.'statistics', 'private-'); + $channelName = Str::after(DashboardLogger::LOG_CHANNEL_PREFIX.'statistics', 'private-'); return new PrivateChannel($channelName); } diff --git a/src/WebSockets/Channels/Channel.php b/src/WebSockets/Channels/Channel.php index 8735d78..9415b0b 100644 --- a/src/WebSockets/Channels/Channel.php +++ b/src/WebSockets/Channels/Channel.php @@ -3,6 +3,7 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Channels; use stdClass; +use Illuminate\Support\Str; use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature; @@ -38,7 +39,7 @@ class Channel $signature .= ":{$payload->channel_data}"; } - if (str_after($payload->auth, ':') !== hash_hmac('sha256', $signature, $connection->app->secret)) { + if (Str::after($payload->auth, ':') !== hash_hmac('sha256', $signature, $connection->app->secret)) { throw new InvalidSignature(); } } diff --git a/src/WebSockets/Channels/ChannelManagers/ArrayChannelManager.php b/src/WebSockets/Channels/ChannelManagers/ArrayChannelManager.php index d529adf..0423cb4 100644 --- a/src/WebSockets/Channels/ChannelManagers/ArrayChannelManager.php +++ b/src/WebSockets/Channels/ChannelManagers/ArrayChannelManager.php @@ -2,6 +2,8 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManagers; +use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\WebSockets\Channels\Channel; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; @@ -34,11 +36,11 @@ class ArrayChannelManager implements ChannelManager protected function determineChannelClass(string $channelName): string { - if (starts_with($channelName, 'private-')) { + if (Str::startsWith($channelName, 'private-')) { return PrivateChannel::class; } - if (starts_with($channelName, 'presence-')) { + if (Str::startsWith($channelName, 'presence-')) { return PresenceChannel::class; } @@ -67,18 +69,18 @@ class ArrayChannelManager implements ChannelManager /* * Remove the connection from all channels. */ - collect(array_get($this->channels, $connection->app->id, []))->each->unsubscribe($connection); + collect(Arr::get($this->channels, $connection->app->id, []))->each->unsubscribe($connection); /* * Unset all channels that have no connections so we don't leak memory. */ - collect(array_get($this->channels, $connection->app->id, [])) + collect(Arr::get($this->channels, $connection->app->id, [])) ->reject->hasConnections() ->each(function (Channel $channel, string $channelName) use ($connection) { unset($this->channels[$connection->app->id][$channelName]); }); - if (count(array_get($this->channels, $connection->app->id, [])) === 0) { + if (count(Arr::get($this->channels, $connection->app->id, [])) === 0) { unset($this->channels[$connection->app->id]); } } diff --git a/src/WebSockets/Messages/PusherChannelProtocolMessage.php b/src/WebSockets/Messages/PusherChannelProtocolMessage.php index b2f3cb9..a2b7b25 100644 --- a/src/WebSockets/Messages/PusherChannelProtocolMessage.php +++ b/src/WebSockets/Messages/PusherChannelProtocolMessage.php @@ -3,6 +3,7 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Messages; use stdClass; +use Illuminate\Support\Str; use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; @@ -28,7 +29,7 @@ class PusherChannelProtocolMessage implements PusherMessage public function respond() { - $eventName = camel_case(str_after($this->payload->event, ':')); + $eventName = Str::camel(Str::after($this->payload->event, ':')); if (method_exists($this, $eventName)) { call_user_func([$this, $eventName], $this->connection, $this->payload->data ?? new stdClass()); diff --git a/src/WebSockets/Messages/PusherClientMessage.php b/src/WebSockets/Messages/PusherClientMessage.php index 8a1ac7d..5e30f7e 100644 --- a/src/WebSockets/Messages/PusherClientMessage.php +++ b/src/WebSockets/Messages/PusherClientMessage.php @@ -3,6 +3,7 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Messages; use stdClass; +use Illuminate\Support\Str; use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; @@ -29,7 +30,7 @@ class PusherClientMessage implements PusherMessage public function respond() { - if (! starts_with($this->payload->event, 'client-')) { + if (! Str::startsWith($this->payload->event, 'client-')) { return; } diff --git a/src/WebSockets/Messages/PusherMessageFactory.php b/src/WebSockets/Messages/PusherMessageFactory.php index 1c4d7a1..fc64ae3 100644 --- a/src/WebSockets/Messages/PusherMessageFactory.php +++ b/src/WebSockets/Messages/PusherMessageFactory.php @@ -2,6 +2,7 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Messages; +use Illuminate\Support\Str; use Ratchet\ConnectionInterface; use Ratchet\RFC6455\Messaging\MessageInterface; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; @@ -15,7 +16,7 @@ class PusherMessageFactory { $payload = json_decode($message->getPayload()); - return starts_with($payload->event, 'pusher:') + return Str::startsWith($payload->event, 'pusher:') ? new PusherChannelProtocolMessage($payload, $connection, $channelManager) : new PusherClientMessage($payload, $connection, $channelManager); } diff --git a/tests/ClientProviders/ConfigAppProviderTest.php b/tests/ClientProviders/ConfigAppProviderTest.php index f8909db..3beb8b6 100644 --- a/tests/ClientProviders/ConfigAppProviderTest.php +++ b/tests/ClientProviders/ConfigAppProviderTest.php @@ -10,7 +10,7 @@ class ConfigAppProviderTest extends TestCase /** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider */ protected $configAppProvider; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Commands/CleanStatisticsTest.php b/tests/Commands/CleanStatisticsTest.php index 0c7fd28..ffe70c6 100644 --- a/tests/Commands/CleanStatisticsTest.php +++ b/tests/Commands/CleanStatisticsTest.php @@ -10,7 +10,7 @@ use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; class CleanStatisticsTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/TestCase.php b/tests/TestCase.php index d863cba..f37d10d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -19,7 +19,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase /** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */ protected $channelManager; - public function setUp() + public function setUp(): void { parent::setUp();