mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 05:54:03 +00:00
Rename copyAuthState to copyAuthProperties
This commit is contained in:
parent
23149473a9
commit
64538eadaa
2 changed files with 10 additions and 9 deletions
|
|
@ -91,11 +91,11 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
||||||
// contract gets the same tenant broadcaster that the manager uses, instead of the stale central one.
|
// contract gets the same tenant broadcaster that the manager uses, instead of the stale central one.
|
||||||
// The closure runs immediately (the extended singleton is already resolved), and it's also what makes
|
// The closure runs immediately (the extended singleton is already resolved), and it's also what makes
|
||||||
// channel auth work in tenant context -- the broadcaster resolved here gets cached as the tenant
|
// channel auth work in tenant context -- the broadcaster resolved here gets cached as the tenant
|
||||||
// manager's default driver and receives the central broadcaster's auth state (see copyAuthState()).
|
// manager's default driver and receives the central broadcaster's auth properties (see copyAuthProperties()).
|
||||||
$this->app->extend(BroadcasterContract::class, function (BroadcasterContract $centralBroadcaster) {
|
$this->app->extend(BroadcasterContract::class, function (BroadcasterContract $centralBroadcaster) {
|
||||||
$tenantBroadcaster = $this->app->make(BroadcastManager::class)->connection();
|
$tenantBroadcaster = $this->app->make(BroadcastManager::class)->connection();
|
||||||
|
|
||||||
$this->copyAuthState($centralBroadcaster, $tenantBroadcaster);
|
$this->copyAuthProperties($centralBroadcaster, $tenantBroadcaster);
|
||||||
|
|
||||||
return $tenantBroadcaster;
|
return $tenantBroadcaster;
|
||||||
});
|
});
|
||||||
|
|
@ -107,18 +107,19 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the auth state (the channel auth closures, their options, and the authenticated user
|
* Copy the channel and auth properties (the registered channel auth closures, their
|
||||||
* callback) from one broadcaster to another. A freshly resolved broadcaster has no auth state,
|
* options, and the authenticated user callback) from one broadcaster to another. A
|
||||||
* so without the copying, channel auth and user auth would stop working (403) in tenant context.
|
* freshly resolved broadcaster has none of these set, so without the copying, channel
|
||||||
|
* auth and user auth would stop working (403) in tenant context.
|
||||||
*
|
*
|
||||||
* The auth state is stored on the abstract Broadcaster class, not in the Broadcaster
|
* These properties are stored on the abstract Broadcaster class, not in the Broadcaster
|
||||||
* contract, and it's stored in protected properties. Because of that, we have
|
* contract, and they're stored in protected properties. Because of that, we have
|
||||||
* to check that both broadcasters are instances of the abstract Broadcaster class and
|
* to check that both broadcasters are instances of the abstract Broadcaster class and
|
||||||
* use invade() to access the protected properties (for the $channels property, there
|
* use invade() to access the protected properties (for the $channels property, there
|
||||||
* is a public accessor -- getChannels() -- but since invade is already used here,
|
* is a public accessor -- getChannels() -- but since invade is already used here,
|
||||||
* we access the property directly for consistency).
|
* we access the property directly for consistency).
|
||||||
*/
|
*/
|
||||||
protected function copyAuthState(BroadcasterContract $from, BroadcasterContract $to): void
|
protected function copyAuthProperties(BroadcasterContract $from, BroadcasterContract $to): void
|
||||||
{
|
{
|
||||||
if (! $from instanceof Broadcaster || ! $to instanceof Broadcaster) {
|
if (! $from instanceof Broadcaster || ! $to instanceof Broadcaster) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ test('tenant broadcast manager receives the custom driver creators of the centra
|
||||||
expect(array_keys(invade(app(BroadcastManager::class))->customCreators))->toEqualCanonicalizing($originalDrivers);
|
expect(array_keys(invade(app(BroadcastManager::class))->customCreators))->toEqualCanonicalizing($originalDrivers);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenant broadcasters receive the auth state of the broadcaster bound in central context', function () {
|
test('tenant broadcasters receive the auth properties of the broadcaster bound in central context', function () {
|
||||||
config([
|
config([
|
||||||
'tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class],
|
'tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class],
|
||||||
'broadcasting.default' => 'testing',
|
'broadcasting.default' => 'testing',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue