mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-07 01:24:04 +00:00
Resolve (and cache) tenant broadcasters once per tenancy initialization instead of re-resolving them every time
TenancyBroadcastManager now overrides resolve() (only to pass the central channels to the newly resolved broadcasters) instead of get(), so broadcasters stay cached for the duration of the tenant's context. Remove TenancyBroadcastManager::$tenantBroadcasters -- all broadcasters now inherit the central channels, so even custom drivers work without any additional configuration/registration. Channels registered via Broadcast::channel() in tenant context are no longer lost on subsequent broadcaster retrievals (e.g. during /broadcasting/auth). Added a dedicated test for this,
This commit is contained in:
parent
24aeb23431
commit
2a0464d694
3 changed files with 71 additions and 62 deletions
|
|
@ -15,7 +15,7 @@ use Stancl\Tenancy\Overrides\TenancyBroadcastManager;
|
|||
|
||||
/**
|
||||
* Maps tenant properties to broadcasting config and overrides
|
||||
* the BroadcastManager binding with TenancyBroadcastManager.
|
||||
* the BroadcastManager and Broadcaster bindings with tenant-aware instances.
|
||||
*
|
||||
* @see TenancyBroadcastManager
|
||||
*/
|
||||
|
|
@ -73,8 +73,9 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
|||
|
||||
$this->setConfig($tenant);
|
||||
|
||||
// Make BroadcastManager resolve to TenancyBroadcastManager. The manager:
|
||||
// - resolves fresh broadcasters so that the updated (tenant) broadcasting config is used while broadcasting
|
||||
// Make BroadcastManager resolve to a fresh TenancyBroadcastManager. The new manager:
|
||||
// - has no cached broadcasters, so its broadcasters get resolved using the updated (tenant)
|
||||
// broadcasting config and stay cached for the duration of the tenant's context
|
||||
// - makes the tenant broadcasters inherit the channels of the original (central) broadcaster
|
||||
// (since newly resolved broadcasters don't receive any channels by default, broadcasting on
|
||||
// channels registered in central context, e.g. in routes/channels.php, would otherwise not
|
||||
|
|
@ -93,11 +94,8 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
|||
});
|
||||
|
||||
// Swap the currently bound Broadcaster singleton (resolved earlier with the central credentials)
|
||||
// for one resolved through the tenant BroadcastManager, so that anything resolving the Broadcaster
|
||||
// contract gets a broadcaster that uses the tenant's credentials instead of the stale central one.
|
||||
// Unlike broadcasters resolved through the manager (re-resolved on each call), this instance is
|
||||
// resolved once, so credential changes made later in tenant context don't affect it until tenancy
|
||||
// is reinitialized.
|
||||
// for the tenant BroadcastManager's default broadcaster, so that anything resolving the Broadcaster
|
||||
// contract gets the same tenant broadcaster that the manager uses, instead of the stale central one.
|
||||
$this->app->extend(Broadcaster::class, function () {
|
||||
return $this->app->make(BroadcastManager::class)->connection();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue