Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:beyondcode/laravel-websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Feb 27, 2019
2 parents 82bba5b + 3ec6c0a commit f26f892
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 22 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions src/HttpApi/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Pusher\Pusher;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use GuzzleHttp\Psr7\Response;
use Ratchet\ConnectionInterface;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function onOpen(ConnectionInterface $connection, RequestInterface $reques

$this->contentLength = $this->findContentLength($request->getHeaders());

$this->requestBuffer = (string)$request->getBody();
$this->requestBuffer = (string) $request->getBody();

$this->checkContentLength($connection);
}
Expand Down Expand Up @@ -123,7 +124,7 @@ protected function ensureValidSignature(Request $request)
*
* 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());
Expand Down
3 changes: 2 additions & 1 deletion src/HttpApi/Controllers/FetchChannelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +17,7 @@ public function __invoke(Request $request)

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);
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/Statistics/Events/StatisticsUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function broadcastWith()

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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/WebSockets/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function verifySignature(ConnectionInterface $connection, stdClass $pa
$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();
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/WebSockets/Channels/ChannelManagers/ArrayChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,11 +36,11 @@ public function find(string $appId, string $channelName): ?Channel

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;
}

Expand Down Expand Up @@ -67,18 +69,18 @@ public function removeFromAllChannels(ConnectionInterface $connection)
/*
* 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]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/WebSockets/Messages/PusherChannelProtocolMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;

use stdClass;
use Illuminate\Support\Str;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;

Expand All @@ -28,7 +29,7 @@ public function __construct(stdClass $payload, ConnectionInterface $connection,

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());
Expand Down
3 changes: 2 additions & 1 deletion src/WebSockets/Messages/PusherClientMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ public function __construct(stdClass $payload, ConnectionInterface $connection,

public function respond()
{
if (! starts_with($this->payload->event, 'client-')) {
if (! Str::startsWith($this->payload->event, 'client-')) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/WebSockets/Messages/PusherMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,7 @@ public static function createForMessage(
{
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ClientProviders/ConfigAppProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConfigAppProviderTest extends TestCase
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider */
protected $configAppProvider;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Commands/CleanStatisticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class CleanStatisticsTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit f26f892

Please sign in to comment.