-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* slim channel manager * rename connection manager * add channel connection manager * channels manage connections * Fix code styling
- Loading branch information
Showing
19 changed files
with
252 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Contracts; | ||
|
||
interface ChannelConnectionManager | ||
{ | ||
/** | ||
* Add a connection. | ||
*/ | ||
public function add(Connection $connection): void; | ||
|
||
/** | ||
* Remove a connection. | ||
*/ | ||
public function remove(Connection $connection): void; | ||
|
||
/** | ||
* Get all the connections. | ||
*/ | ||
public function all(): array; | ||
|
||
/** | ||
* Flush the channel connection manager. | ||
*/ | ||
public function flush(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Managers; | ||
|
||
use Laravel\Reverb\Contracts\ChannelConnectionManager; | ||
use Laravel\Reverb\Contracts\Connection; | ||
|
||
class ArrayChannelConnectionManager implements ChannelConnectionManager | ||
{ | ||
/** | ||
* Connection store. | ||
* | ||
* @var array<string, array<string, \Laravel\Reverb\Connection>> | ||
*/ | ||
protected $connections = []; | ||
|
||
/** | ||
* Add a connection. | ||
*/ | ||
public function add(Connection $connection): void | ||
{ | ||
$this->connections[$connection->identifier()] = $connection; | ||
} | ||
|
||
/** | ||
* Remove a connection. | ||
*/ | ||
public function remove(Connection $connection): void | ||
{ | ||
unset($this->connections[$connection->identifier()]); | ||
} | ||
|
||
/** | ||
* Get all the connections. | ||
*/ | ||
public function all(): array | ||
{ | ||
return $this->connections; | ||
} | ||
|
||
/** | ||
* Flush the channel connection manager. | ||
*/ | ||
public function flush(): void | ||
{ | ||
$this->connections = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace Laravel\Reverb\Managers; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\App; | ||
use Laravel\Reverb\Application; | ||
use Laravel\Reverb\Channels\Channel; | ||
use Laravel\Reverb\Channels\ChannelBroker; | ||
use Laravel\Reverb\Concerns\InteractsWithApplications; | ||
use Laravel\Reverb\Contracts\ApplicationProvider; | ||
use Laravel\Reverb\Contracts\ChannelManager as ChannelManagerInterface; | ||
use Laravel\Reverb\Contracts\Connection; | ||
|
||
class ArrayChannelManager implements ChannelManagerInterface | ||
{ | ||
use InteractsWithApplications; | ||
|
||
/** | ||
* Application store. | ||
* | ||
* @var array<string, array<string, array<string, \Laravel\Reverb\Channels\Channel>>> | ||
*/ | ||
protected $applications = []; | ||
|
||
/** | ||
* The appliation instance. | ||
* | ||
* @var \Laravel\Reverb\Application | ||
*/ | ||
protected $application; | ||
|
||
/** | ||
* Get the application instance. | ||
*/ | ||
public function app(): ?Application | ||
{ | ||
return $this->application; | ||
} | ||
|
||
/** | ||
* Get all the channels. | ||
*/ | ||
public function all(): Collection | ||
{ | ||
return collect($this->channels()); | ||
} | ||
|
||
/** | ||
* Find the given channel | ||
*/ | ||
public function find(string $channel): Channel | ||
{ | ||
return $this->channels($channel); | ||
} | ||
|
||
/** | ||
* Unsubscribe from all channels. | ||
*/ | ||
public function unsubscribeFromAll(Connection $connection): void | ||
{ | ||
foreach ($this->channels() as $channel) { | ||
$channel->unsubscribe($connection); | ||
} | ||
} | ||
|
||
/** | ||
* Get the given channel. | ||
*/ | ||
public function channel(string $channel): array | ||
{ | ||
return $this->channels($channel); | ||
} | ||
|
||
/** | ||
* Get the channels. | ||
*/ | ||
public function channels(string $channel = null): array|Channel | ||
{ | ||
if (! isset($this->applications[$this->application->id()])) { | ||
$this->applications[$this->application->id()] = []; | ||
} | ||
|
||
$channels = $this->applications[$this->application->id()]; | ||
|
||
if ($channel) { | ||
if (! isset($channels[$channel])) { | ||
$this->applications[$this->application->id()][$channel] = ChannelBroker::create($channel); | ||
} | ||
|
||
return $this->applications[$this->application->id()][$channel]; | ||
} | ||
|
||
return $channels ?: []; | ||
} | ||
|
||
/** | ||
* Flush the channel manager repository. | ||
*/ | ||
public function flush(): void | ||
{ | ||
App::make(ApplicationProvider::class) | ||
->all() | ||
->each(function (Application $application) { | ||
$this->applications[$application->id()] = []; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.