1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 18:04:03 +00:00

Polish comments

This commit is contained in:
lukinovec 2026-04-03 13:40:44 +02:00
parent c831393589
commit ef476c5361
2 changed files with 19 additions and 14 deletions

View file

@ -88,7 +88,7 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
return $tenantBroadcastManager; return $tenantBroadcastManager;
}); });
// Swap currently bound Broadcaster instance for one that's resolved through the tenant broadcast manager. // Swap currently bound Broadcaster instance for one that's resolved through the tenant BroadcastManager.
// Note that updating broadcasting config (credentials) in tenant context doesn't update the credentials // Note that updating broadcasting config (credentials) in tenant context doesn't update the credentials
// used by the bound Broadcaster instance. If you need to e.g. send a notification in response to // used by the bound Broadcaster instance. If you need to e.g. send a notification in response to
// updating tenant's broadcasting credentials in tenant context, it's recommended to // updating tenant's broadcasting credentials in tenant context, it's recommended to
@ -99,7 +99,7 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
// Clear the resolved Broadcast facade's Illuminate\Contracts\Broadcasting\Factory instance // Clear the resolved Broadcast facade's Illuminate\Contracts\Broadcasting\Factory instance
// so that it gets re-resolved as TenancyBroadcastManager instead of the central BroadcastManager // so that it gets re-resolved as TenancyBroadcastManager instead of the central BroadcastManager
// when used e.g. in the Broadcast::auth() call in BroadcastController::authenticate (/broadcasting/auth). // when used. E.g. the Broadcast::auth() call in BroadcastController::authenticate (/broadcasting/auth).
Broadcast::clearResolvedInstance(BroadcastingFactory::class); Broadcast::clearResolvedInstance(BroadcastingFactory::class);
} }
@ -109,7 +109,7 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
$this->app->singleton(BroadcastManager::class, fn (Application $app) => $this->originalBroadcastManager); $this->app->singleton(BroadcastManager::class, fn (Application $app) => $this->originalBroadcastManager);
$this->app->singleton(Broadcaster::class, fn (Application $app) => $this->originalBroadcaster); $this->app->singleton(Broadcaster::class, fn (Application $app) => $this->originalBroadcaster);
// Clear the resolved Broadcast facade instance so that it gets re-resolved as the central broadcast manager // Clear the resolved Broadcast facade instance so that it gets re-resolved as the central BroadcastManager
Broadcast::clearResolvedInstance(BroadcastingFactory::class); Broadcast::clearResolvedInstance(BroadcastingFactory::class);
$this->unsetConfig(); $this->unsetConfig();

View file

@ -11,7 +11,7 @@ use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
/** /**
* BroadcastManager override that always re-resolves the broadcasters in static::$tenantBroadcasters * BroadcastManager override that always re-resolves the broadcasters in static::$tenantBroadcasters
* when attempting to retrieve them and passes the channels of the original (central) broadcaster * when attempting to retrieve them and passes the channels of the original (central) broadcaster
* to the broadcasters newly resolved in tenant context. * to the newly resolved (tenant) broadcasters.
* *
* Affects calls that use app(BroadcastManager::class)->get(). * Affects calls that use app(BroadcastManager::class)->get().
* *
@ -23,11 +23,12 @@ class TenancyBroadcastManager extends BroadcastManager
* Names of broadcasters that * Names of broadcasters that
* - should always be recreated using $this->resolve(), even when they're cached and available * - should always be recreated using $this->resolve(), even when they're cached and available
* in $this->drivers so that when you update broadcasting config in the tenant context, * in $this->drivers so that when you update broadcasting config in the tenant context,
* the updated config/credentials will be used for broadcasting in the same context. * the updated config/credentials will be used for broadcasting immediately.
* Note that in cases like this, only direct config changes are reflected immediately. * Note that in cases like this, only direct config changes are reflected right away.
* For the broadcasters to reflect tenant property changes made in tenant context, * For the broadcasters to reflect tenant property changes made in tenant context,
* you still have to reinitialize tenancy after updating the tenant properties intended * you still have to reinitialize tenancy after updating the tenant properties intended
* for broadcasting config mapping, since the properties are only mapped to config on BroadcastingConfigBootstrapper::bootstrap(). * to be mapped to broadcasting config, since the properties are only mapped to config
* on BroadcastingConfigBootstrapper::bootstrap().
* - should inherit the original broadcaster's channels (= the channels registered in * - should inherit the original broadcaster's channels (= the channels registered in
* the central context, e.g. in routes/channels.php, before this manager overrides the bound BroadcastManager). * the central context, e.g. in routes/channels.php, before this manager overrides the bound BroadcastManager).
*/ */
@ -35,7 +36,8 @@ class TenancyBroadcastManager extends BroadcastManager
/** /**
* Override the get method so that the broadcasters in static::$tenantBroadcasters * Override the get method so that the broadcasters in static::$tenantBroadcasters
* receive the original (central) broadcaster's channels and always get freshly resolved. * - receive the original (central) broadcaster's channels
* - always get freshly resolved.
*/ */
protected function get($name) protected function get($name)
{ {
@ -45,9 +47,10 @@ class TenancyBroadcastManager extends BroadcastManager
$newBroadcaster = $this->resolve($name); $newBroadcaster = $this->resolve($name);
// Give the channels of the original (central) broadcaster to the newly resolved one. // Give the channels of the original (central) broadcaster to the newly resolved one.
//
// Broadcasters only have to implement the Illuminate\Contracts\Broadcasting\Broadcaster contract // Broadcasters only have to implement the Illuminate\Contracts\Broadcasting\Broadcaster contract
// which doesn't require the channels property, so passing the channels is only // which doesn't require the channels property, so passing the channels is only needed for
// needed for Illuminate\Broadcasting\Broadcasters\Broadcaster instances. // Illuminate\Broadcasting\Broadcasters\Broadcaster instances (= all the default broadcasters, e.g. PusherBroadcaster).
if ($originalBroadcaster instanceof Broadcaster && $newBroadcaster instanceof Broadcaster) { if ($originalBroadcaster instanceof Broadcaster && $newBroadcaster instanceof Broadcaster) {
$this->passChannelsFromOriginalBroadcaster($originalBroadcaster, $newBroadcaster); $this->passChannelsFromOriginalBroadcaster($originalBroadcaster, $newBroadcaster);
} }
@ -58,10 +61,12 @@ class TenancyBroadcastManager extends BroadcastManager
return parent::get($name); return parent::get($name);
} }
// The newly resolved broadcasters don't automatically receive the channels registered /**
// in central context (e.g. Broadcast::channel() in routes/channels.php), so the channels * The newly resolved broadcasters don't automatically receive the channels registered
// have to be obtained from the original (central) broadcaster and manually passed to the new broadcasters * in central context (e.g. Broadcast::channel() in routes/channels.php), so the channels
// (broadcasting using a broadcaster with no channels results in a 403 error on Broadcast::auth()). * have to be obtained from the original (central) broadcaster and manually passed to the new broadcasters
* (broadcasting using a broadcaster with no channels results in a 403 error on Broadcast::auth()).
*/
protected function passChannelsFromOriginalBroadcaster(Broadcaster $originalBroadcaster, Broadcaster $newBroadcaster): void protected function passChannelsFromOriginalBroadcaster(Broadcaster $originalBroadcaster, Broadcaster $newBroadcaster): void
{ {
// invade() because channels can't be retrieved through any of the broadcaster's public methods // invade() because channels can't be retrieved through any of the broadcaster's public methods