2018-11-24 00:25:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BeyondCode\LaravelWebSockets\ClientProviders;
|
|
|
|
|
|
2018-11-24 00:53:20 +00:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
2018-11-24 00:25:40 +00:00
|
|
|
class ConfigClientProvider implements ClientProvider
|
|
|
|
|
{
|
2018-11-24 00:53:20 +00:00
|
|
|
public function findByAppId(int $appId): ?Client
|
|
|
|
|
{
|
|
|
|
|
$clientAttributes = $this
|
|
|
|
|
->allClients()
|
|
|
|
|
->firstWhere('app_id', $appId);
|
|
|
|
|
|
|
|
|
|
return $this->instanciate($clientAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findByAppKey(string $appKey): ?Client
|
2018-11-24 00:25:40 +00:00
|
|
|
{
|
2018-11-24 00:53:20 +00:00
|
|
|
$clientAttributes = $this
|
|
|
|
|
->allClients()
|
|
|
|
|
->firstWhere('app_key', $appKey);
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-11-24 00:53:20 +00:00
|
|
|
return $this->instanciate($clientAttributes);
|
|
|
|
|
}
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-11-24 00:53:20 +00:00
|
|
|
protected function allClients(): Collection
|
|
|
|
|
{
|
|
|
|
|
return collect(config('websockets.clients'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function instanciate(?array $clientAttributes): ?Client
|
|
|
|
|
{
|
|
|
|
|
if (! $clientAttributes) {
|
2018-11-24 00:25:40 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Client(
|
2018-11-24 00:53:20 +00:00
|
|
|
$clientAttributes['app_id'],
|
|
|
|
|
$clientAttributes['app_key'],
|
|
|
|
|
$clientAttributes['app_secret']
|
2018-11-24 00:25:40 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|