renaming clients to apps
This commit is contained in:
parent
0bff2f9f14
commit
e90e86798c
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\ConfigClientProvider;
|
use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
|
@ -10,12 +10,12 @@ return [
|
||||||
*
|
*
|
||||||
* You should make sure that the app id is numeric.
|
* You should make sure that the app id is numeric.
|
||||||
*/
|
*/
|
||||||
'clients' => [
|
'apps' => [
|
||||||
[
|
[
|
||||||
|
'id' => env('PUSHER_APP_ID'),
|
||||||
'name' => env('APP_NAME'),
|
'name' => env('APP_NAME'),
|
||||||
'app_id' => env('PUSHER_APP_ID'),
|
'key' => env('PUSHER_APP_KEY'),
|
||||||
'app_key' => env('PUSHER_APP_KEY'),
|
'ecret' => env('PUSHER_APP_SECRET')
|
||||||
'app_secret' => env('PUSHER_APP_SECRET')
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ return [
|
||||||
* You can create a custom provider by implementing the
|
* You can create a custom provider by implementing the
|
||||||
* `ClientProvier` interface.
|
* `ClientProvier` interface.
|
||||||
*/
|
*/
|
||||||
'client_provider' => ConfigClientProvider::class,
|
'client_provider' => ConfigAppProvider::class,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This array contains the hosts of which you want to allow incoming requests.
|
* This array contains the hosts of which you want to allow incoming requests.
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\ClientProviders;
|
namespace BeyondCode\LaravelWebSockets\Apps;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
|
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
|
||||||
|
|
||||||
class Client
|
class App
|
||||||
{
|
{
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $appId;
|
public $appId;
|
||||||
|
|
@ -18,14 +18,14 @@ class Client
|
||||||
/** @var string|null */
|
/** @var string|null */
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
public static function findByAppId(int $appId)
|
public static function findById(int $appId)
|
||||||
{
|
{
|
||||||
return app(ClientProvider::class)->findByAppId($appId);
|
return app(AppProvider::class)->findById($appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findByAppKey(string $appKey): ?Client
|
public static function findByKey(string $appKey): ?App
|
||||||
{
|
{
|
||||||
return app(ClientProvider::class)->findByAppKey($appKey);
|
return app(AppProvider::class)->findByKey($appKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct($appId, string $appKey, string $appSecret, ?string $name)
|
public function __construct($appId, string $appKey, string $appSecret, ?string $name)
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeyondCode\LaravelWebSockets\Apps;
|
||||||
|
|
||||||
|
interface AppProvider
|
||||||
|
{
|
||||||
|
/** @return array[BeyondCode\LaravelWebSockets\ClientProviders\Client] */
|
||||||
|
public function all(): array;
|
||||||
|
|
||||||
|
public function findById(int $appId): ?App;
|
||||||
|
|
||||||
|
public function findByKey(string $appKey): ?App;
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\ClientProviders;
|
namespace BeyondCode\LaravelWebSockets\Apps;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class ConfigClientProvider implements ClientProvider
|
class ConfigAppProvider implements AppProvider
|
||||||
{
|
{
|
||||||
/** @var Collection */
|
/** @var Collection */
|
||||||
protected $clients;
|
protected $clients;
|
||||||
|
|
@ -23,34 +23,35 @@ class ConfigClientProvider implements ClientProvider
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
public function findByAppId(int $appId): ?Client
|
|
||||||
|
public function findById(int $appId): ?App
|
||||||
{
|
{
|
||||||
$clientAttributes = $this
|
$clientAttributes = $this
|
||||||
->clients
|
->clients
|
||||||
->firstWhere('app_id', $appId);
|
->firstWhere('id', $appId);
|
||||||
|
|
||||||
return $this->instanciate($clientAttributes);
|
return $this->instanciate($clientAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByAppKey(string $appKey): ?Client
|
public function findByKey(string $appKey): ?App
|
||||||
{
|
{
|
||||||
$clientAttributes = $this
|
$clientAttributes = $this
|
||||||
->clients
|
->clients
|
||||||
->firstWhere('app_key', $appKey);
|
->firstWhere('key', $appKey);
|
||||||
|
|
||||||
return $this->instanciate($clientAttributes);
|
return $this->instanciate($clientAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function instanciate(?array $clientAttributes): ?Client
|
protected function instanciate(?array $clientAttributes): ?App
|
||||||
{
|
{
|
||||||
if (! $clientAttributes) {
|
if (! $clientAttributes) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Client(
|
return new App(
|
||||||
$clientAttributes['app_id'],
|
$clientAttributes['id'],
|
||||||
$clientAttributes['app_key'],
|
$clientAttributes['key'],
|
||||||
$clientAttributes['app_secret'],
|
$clientAttributes['secret'],
|
||||||
$clientAttributes['name'] ?? null
|
$clientAttributes['name'] ?? null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\ClientProviders;
|
|
||||||
|
|
||||||
|
|
||||||
interface ClientProvider
|
|
||||||
{
|
|
||||||
/** @return array[BeyondCode\LaravelWebSockets\ClientProviders\Client] */
|
|
||||||
public function all(): array;
|
|
||||||
|
|
||||||
public function findByAppId(int $appId): ?Client;
|
|
||||||
|
|
||||||
public function findByAppKey(string $appKey): ?Client;
|
|
||||||
}
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
|
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\ClientProvider;
|
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
|
||||||
|
|
||||||
class ShowDashboard
|
class ShowDashboard
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request, ClientProvider $clients)
|
public function __invoke(Request $request, AppProvider $clients)
|
||||||
{
|
{
|
||||||
return view('websockets::dashboard', [
|
return view('websockets::dashboard', [
|
||||||
'clients' => $clients->all(),
|
'clients' => $clients->all(),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
|
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\Client;
|
use BeyondCode\LaravelWebSockets\Apps\App;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
|
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
|
||||||
use BeyondCode\LaravelWebSockets\Events\ExceptionThrown;
|
use BeyondCode\LaravelWebSockets\Events\ExceptionThrown;
|
||||||
use BeyondCode\LaravelWebSockets\QueryParameters;
|
use BeyondCode\LaravelWebSockets\QueryParameters;
|
||||||
|
|
@ -77,7 +77,7 @@ abstract class Controller implements HttpServerInterface
|
||||||
|
|
||||||
public function ensureValidAppId(string $appId)
|
public function ensureValidAppId(string $appId)
|
||||||
{
|
{
|
||||||
if (!$client = Client::findByAppId($appId)) {
|
if (!$client = App::findById($appId)) {
|
||||||
throw new HttpException(401, "Unknown app id `{$appId}` provided.");
|
throw new HttpException(401, "Unknown app id `{$appId}` provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ abstract class Controller implements HttpServerInterface
|
||||||
"&auth_version={$request->get('auth_version')}" .
|
"&auth_version={$request->get('auth_version')}" .
|
||||||
"&body_md5={$bodyMd5}";
|
"&body_md5={$bodyMd5}";
|
||||||
|
|
||||||
$authSignature = hash_hmac('sha256', $signature, Client::findByAppId($request->get('appId'))->appSecret);
|
$authSignature = hash_hmac('sha256', $signature, App::findById($request->get('appId'))->appSecret);
|
||||||
|
|
||||||
if ($authSignature !== $request->get('auth_signature')) {
|
if ($authSignature !== $request->get('auth_signature')) {
|
||||||
throw new HttpException(401, 'Invalid auth signature provided.');
|
throw new HttpException(401, 'Invalid auth signature provided.');
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use BeyondCode\LaravelWebSockets\QueryParameters;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
use Ratchet\RFC6455\Messaging\MessageInterface;
|
use Ratchet\RFC6455\Messaging\MessageInterface;
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\Client;
|
use BeyondCode\LaravelWebSockets\Apps\App;
|
||||||
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
||||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
|
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
|
||||||
use Ratchet\WebSocket\MessageComponentInterface;
|
use Ratchet\WebSocket\MessageComponentInterface;
|
||||||
|
|
@ -58,7 +58,7 @@ class WebSocketHandler implements MessageComponentInterface
|
||||||
{
|
{
|
||||||
$appKey = QueryParameters::create($connection->httpRequest)->get('appKey');
|
$appKey = QueryParameters::create($connection->httpRequest)->get('appKey');
|
||||||
|
|
||||||
if (!$client = Client::findByAppKey($appKey)) {
|
if (!$client = App::findByKey($appKey)) {
|
||||||
throw new UnknownAppKey($appKey);
|
throw new UnknownAppKey($appKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
|
||||||
use BeyondCode\LaravelWebSockets\Server\Router;
|
use BeyondCode\LaravelWebSockets\Server\Router;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\ClientProvider;
|
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ class WebSocketsServiceProvider extends ServiceProvider
|
||||||
return new ChannelManager();
|
return new ChannelManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton(ClientProvider::class, function() {
|
$this->app->singleton(AppProvider::class, function() {
|
||||||
return app(config('websockets.client_provider'));
|
return app(config('websockets.client_provider'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\Client;
|
use BeyondCode\LaravelWebSockets\Apps\App;
|
||||||
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
|
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
|
||||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ class ClientTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_create_a_client()
|
public function it_can_create_a_client()
|
||||||
{
|
{
|
||||||
new Client(1, 'appKey', 'appSecret', 'new');
|
new App(1, 'appKey', 'appSecret', 'new');
|
||||||
|
|
||||||
$this->markTestAsPassed();
|
$this->markTestAsPassed();
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ class ClientTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidClient::class);
|
$this->expectException(InvalidClient::class);
|
||||||
|
|
||||||
new Client(1, '', 'appSecret', 'new');
|
new App(1, '', 'appSecret', 'new');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -29,7 +29,7 @@ class ClientTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidClient::class);
|
$this->expectException(InvalidClient::class);
|
||||||
|
|
||||||
new Client(1, 'appKey', '', 'new');
|
new App(1, 'appKey', '', 'new');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
@ -37,6 +37,6 @@ class ClientTest extends TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidClient::class);
|
$this->expectException(InvalidClient::class);
|
||||||
|
|
||||||
new Client('appId', 'appKey', '', 'new');
|
new App('appId', 'appKey', '', 'new');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,19 +2,19 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\ConfigClientProvider;
|
use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
|
||||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||||
|
|
||||||
class ConfigClientProviderTest extends TestCase
|
class ConfigClientProviderTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var \BeyondCode\LaravelWebSockets\ClientProviders\ConfigClientProvider */
|
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider */
|
||||||
protected $configClientProvider;
|
protected $configClientProvider;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->configClientProvider = new ConfigClientProvider();
|
$this->configClientProvider = new ConfigAppProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Tests;
|
namespace BeyondCode\LaravelWebSockets\Tests;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\ClientProviders\Client;
|
use BeyondCode\LaravelWebSockets\Apps\App;
|
||||||
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
|
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
|
||||||
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ class ConnectionTest extends TestCase
|
||||||
|
|
||||||
$this->pusherServer->onOpen($connection);
|
$this->pusherServer->onOpen($connection);
|
||||||
|
|
||||||
$this->assertInstanceOf(Client::class, $connection->client);
|
$this->assertInstanceOf(App::class, $connection->client);
|
||||||
$this->assertSame(1234, $connection->client->appId);
|
$this->assertSame(1234, $connection->client->appId);
|
||||||
$this->assertSame('TestKey', $connection->client->appKey);
|
$this->assertSame('TestKey', $connection->client->appKey);
|
||||||
$this->assertSame('TestSecret', $connection->client->appSecret);
|
$this->assertSame('TestSecret', $connection->client->appSecret);
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
$app['config']->set('websockets.clients', [
|
$app['config']->set('websockets.clients', [
|
||||||
[
|
[
|
||||||
'name' => 'Test Client',
|
'name' => 'Test Client',
|
||||||
'app_id' => 1234,
|
'id' => 1234,
|
||||||
'app_key' => 'TestKey',
|
'key' => 'TestKey',
|
||||||
'app_secret' => 'TestSecret'
|
'secret' => 'TestSecret'
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue