mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 13:54:03 +00:00
Pass BroadcastManager to override closures (#23)
* pass BroadcastManager to override closures * Improve the broadcaster override syntax in the bootstrapper test * remove unnecessary return --------- Co-authored-by: lukinovec <lukinovec@gmail.com>
This commit is contained in:
parent
d9b63cdf59
commit
00a00a2aff
2 changed files with 7 additions and 11 deletions
|
|
@ -49,7 +49,7 @@ class BroadcastChannelPrefixBootstrapper implements TenancyBootstrapper
|
||||||
// Delete the cached broadcaster, so that the manager uses the new one
|
// Delete the cached broadcaster, so that the manager uses the new one
|
||||||
$this->broadcastManager->purge($broadcaster);
|
$this->broadcastManager->purge($broadcaster);
|
||||||
|
|
||||||
$broadcasterOverride();
|
$broadcasterOverride($this->broadcastManager);
|
||||||
|
|
||||||
// Get the overriden broadcaster
|
// Get the overriden broadcaster
|
||||||
$newBroadcaster = $this->broadcastManager->driver($broadcaster);
|
$newBroadcaster = $this->broadcastManager->driver($broadcaster);
|
||||||
|
|
@ -83,10 +83,8 @@ class BroadcastChannelPrefixBootstrapper implements TenancyBootstrapper
|
||||||
*/
|
*/
|
||||||
public static function pusher(Closure|null $override = null): void
|
public static function pusher(Closure|null $override = null): void
|
||||||
{
|
{
|
||||||
static::$broadcasterOverrides['pusher'] = $override ?? function () {
|
static::$broadcasterOverrides['pusher'] = $override ?? function (BroadcastManager $broadcastManager): void {
|
||||||
$broadcastManager = app(BroadcastManager::class);
|
$broadcastManager->extend('pusher', function ($app, $config) use ($broadcastManager) {
|
||||||
|
|
||||||
return $broadcastManager->extend('pusher', function ($app, $config) use ($broadcastManager) {
|
|
||||||
return new class($broadcastManager->pusher($config)) extends PusherBroadcaster {
|
return new class($broadcastManager->pusher($config)) extends PusherBroadcaster {
|
||||||
protected function formatChannels(array $channels)
|
protected function formatChannels(array $channels)
|
||||||
{
|
{
|
||||||
|
|
@ -125,10 +123,8 @@ class BroadcastChannelPrefixBootstrapper implements TenancyBootstrapper
|
||||||
*/
|
*/
|
||||||
public static function ably(Closure|null $override = null): void
|
public static function ably(Closure|null $override = null): void
|
||||||
{
|
{
|
||||||
static::$broadcasterOverrides['ably'] = $override ?? function () {
|
static::$broadcasterOverrides['ably'] = $override ?? function (BroadcastManager $broadcastManager): void {
|
||||||
$broadcastManager = app(BroadcastManager::class);
|
$broadcastManager->extend('ably', function ($app, $config) use ($broadcastManager) {
|
||||||
|
|
||||||
return $broadcastManager->extend('ably', function ($app, $config) use ($broadcastManager) {
|
|
||||||
return new class($broadcastManager->ably($config)) extends AblyBroadcaster {
|
return new class($broadcastManager->ably($config)) extends AblyBroadcaster {
|
||||||
protected function formatChannels(array $channels)
|
protected function formatChannels(array $channels)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -788,8 +788,8 @@ test('BroadcastChannelPrefixBootstrapper prefixes the channels events are broadc
|
||||||
// Set up the 'testing' broadcaster override
|
// Set up the 'testing' broadcaster override
|
||||||
// Identical to the default Pusher override (BroadcastChannelPrefixBootstrapper::pusher())
|
// Identical to the default Pusher override (BroadcastChannelPrefixBootstrapper::pusher())
|
||||||
// Except for the parent class (TestingBroadcaster instead of PusherBroadcaster)
|
// Except for the parent class (TestingBroadcaster instead of PusherBroadcaster)
|
||||||
BroadcastChannelPrefixBootstrapper::$broadcasterOverrides['testing'] = function () {
|
BroadcastChannelPrefixBootstrapper::$broadcasterOverrides['testing'] = function (BroadcastManager $broadcastManager) {
|
||||||
return app(BroadcastManager::class)->extend('testing', function ($app, $config) {
|
$broadcastManager->extend('testing', function ($app, $config) {
|
||||||
return new class('tenant broadcaster') extends TestingBroadcaster {
|
return new class('tenant broadcaster') extends TestingBroadcaster {
|
||||||
protected function formatChannels(array $channels)
|
protected function formatChannels(array $channels)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue