File "WebsocketProviderAPI.php"
Full Path: /var/www/drive/foundation/src/Websockets/API/WebsocketProviderAPI.php
File size: 1006 B
MIME-type: text/x-php
Charset: utf-8
<?php
namespace Common\Websockets\API;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
abstract class WebsocketProviderAPI
{
protected array $cache = [];
public function __construct(protected array $options = [])
{
}
abstract public function getAllChannels(): Collection;
abstract public function getActiveUsersInChannel(
string $channel,
): Collection;
protected function getClient(): PendingRequest
{
return Http::throwIf($this->options['throw'] ?? false);
}
protected function makeRequestWithCaching(string $path, array $params = [])
{
$cacheKey = $path . json_encode($params);
if (isset($this->cache[$cacheKey])) {
return $this->cache[$cacheKey];
}
$response = $this->getClient()
->get($path, $params)
->json();
$this->cache[$cacheKey] = $response;
return $response;
}
}