1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 19:14:05 +00:00

Remove TenancyBroadcastManager, pass the channel auth closures directly in the Broadcaster extend() closure

Channel auth closures (registered using Broadcast::channel() e.g. in routes/channels.php) are only ever read from the default broadcaster -- both Broadcast::channel() and Broadcast::auth() go through the default broadcaster. TenancyBroadcastManager passed the closures to every broadcaster it resolved, which is pointless -- even in central context, Laravel doesn't do anything like that).

Instead, bind a fresh BroadcastManager and pass the central channel closures to its default broadcaster while extending Broadcaster. So now, tenant context behaves exactly like central context, just with broadcasters resolved using the tenant credentials.

Also update comments.
This commit is contained in:
lukinovec 2026-07-12 11:49:34 +02:00
parent 128a1ad036
commit 9e6e0a988b
3 changed files with 44 additions and 93 deletions

View file

@ -8,7 +8,6 @@ use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Tests\Etc\TestingBroadcaster;
use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Overrides\TenancyBroadcastManager;
use Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
@ -45,22 +44,20 @@ beforeEach(function () use ($cleanup) {
afterEach($cleanup);
test('BroadcastingConfigBootstrapper binds TenancyBroadcastManager to BroadcastManager and reverts the binding when tenancy is ended', function() {
test('BroadcastingConfigBootstrapper binds a fresh BroadcastManager and reverts the binding when tenancy is ended', function() {
config(['tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class]]);
expect(app(BroadcastManager::class))
->toBeInstanceOf(BroadcastManager::class)
->not()->toBeInstanceOf(TenancyBroadcastManager::class);
$centralManager = app(BroadcastManager::class);
tenancy()->initialize(Tenant::create());
expect(app(BroadcastManager::class))->toBeInstanceOf(TenancyBroadcastManager::class);
expect(app(BroadcastManager::class))
->toBeInstanceOf(BroadcastManager::class)
->not()->toBe($centralManager);
tenancy()->end();
expect(app(BroadcastManager::class))
->toBeInstanceOf(BroadcastManager::class)
->not()->toBeInstanceOf(TenancyBroadcastManager::class);
expect(app(BroadcastManager::class))->toBe($centralManager);
});
test('ending tenancy reverts the bound broadcaster to the original instance', function() {