diff --git a/src/Protocols/Pusher/Contracts/ChannelManager.php b/src/Protocols/Pusher/Contracts/ChannelManager.php index 0b76e9cb..4acb2f9e 100644 --- a/src/Protocols/Pusher/Contracts/ChannelManager.php +++ b/src/Protocols/Pusher/Contracts/ChannelManager.php @@ -25,6 +25,11 @@ public function for(Application $application): ChannelManager; */ public function all(): array; + /** + * Determine whether the given channel exists. + */ + public function exists(string $channel): bool; + /** * Find the given channel. */ diff --git a/src/Protocols/Pusher/Managers/ArrayChannelManager.php b/src/Protocols/Pusher/Managers/ArrayChannelManager.php index 0965d337..a8cf694c 100644 --- a/src/Protocols/Pusher/Managers/ArrayChannelManager.php +++ b/src/Protocols/Pusher/Managers/ArrayChannelManager.php @@ -47,6 +47,14 @@ public function all(): array return $this->channels(); } + /** + * Determine whether the given channel exists. + */ + public function exists(string $channel): bool + { + return isset($this->applications[$this->application->id()][$channel]); + } + /** * Find the given channel */ diff --git a/tests/Unit/Protocols/Pusher/Managers/ChannelManagerTest.php b/tests/Unit/Protocols/Pusher/Managers/ChannelManagerTest.php index 787f99a9..638ae60c 100644 --- a/tests/Unit/Protocols/Pusher/Managers/ChannelManagerTest.php +++ b/tests/Unit/Protocols/Pusher/Managers/ChannelManagerTest.php @@ -38,6 +38,13 @@ expect($this->channelManager->all())->toHaveCount(4); }); +it('can determine whether a channel exists', function () { + $this->channelManager->findOrCreate('test-channel-1'); + + expect($this->channelManager->exists('test-channel-1'))->toBeTrue(); + expect($this->channelManager->exists('test-channel-2'))->toBeFalse(); +}); + it('can get all connections subscribed to a channel', function () { $connections = collect(factory(5)) ->each(fn ($connection) => $this->channel->subscribe($connection->connection()));