8889841cAppProvider.php000066600000000531150515670420007520 0ustar00findById($appId); } public static function findByKey(string $appKey): ?self { return app(AppProvider::class)->findByKey($appKey); } public static function findBySecret(string $appSecret): ?self { return app(AppProvider::class)->findBySecret($appSecret); } public function __construct($appId, string $appKey, string $appSecret) { if ($appKey === '') { throw InvalidApp::valueIsRequired('appKey', $appId); } if ($appSecret === '') { throw InvalidApp::valueIsRequired('appSecret', $appId); } $this->id = $appId; $this->key = $appKey; $this->secret = $appSecret; } public function setName(string $appName) { $this->name = $appName; return $this; } public function setHost(string $host) { $this->host = $host; return $this; } public function setPath(string $path) { $this->path = $path; return $this; } public function enableClientMessages(bool $enabled = true) { $this->clientMessagesEnabled = $enabled; return $this; } public function setCapacity(?int $capacity) { $this->capacity = $capacity; return $this; } public function enableStatistics(bool $enabled = true) { $this->statisticsEnabled = $enabled; return $this; } } ConfigAppProvider.php000066600000004026150515670420010651 0ustar00apps = collect(config('websockets.apps')); } /** @return array[\BeyondCode\LaravelWebSockets\AppProviders\App] */ public function all(): array { return $this->apps ->map(function (array $appAttributes) { return $this->instanciate($appAttributes); }) ->toArray(); } public function findById($appId): ?App { $appAttributes = $this ->apps ->firstWhere('id', $appId); return $this->instanciate($appAttributes); } public function findByKey(string $appKey): ?App { $appAttributes = $this ->apps ->firstWhere('key', $appKey); return $this->instanciate($appAttributes); } public function findBySecret(string $appSecret): ?App { $appAttributes = $this ->apps ->firstWhere('secret', $appSecret); return $this->instanciate($appAttributes); } protected function instanciate(?array $appAttributes): ?App { if (! $appAttributes) { return null; } $app = new App( $appAttributes['id'], $appAttributes['key'], $appAttributes['secret'] ); if (isset($appAttributes['name'])) { $app->setName($appAttributes['name']); } if (isset($appAttributes['host'])) { $app->setHost($appAttributes['host']); } if (isset($appAttributes['path'])) { $app->setPath($appAttributes['path']); } $app ->enableClientMessages($appAttributes['enable_client_messages']) ->enableStatistics($appAttributes['enable_statistics']) ->setCapacity($appAttributes['capacity'] ?? null); return $app; } }