mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 08:54:03 +00:00
Delete $broadcaster property from the config bootstrapper, stop overriding the static properties in the constructor
The $broadcaster property essentially had no real purpose, and there's no reason to override the static properties in the constructor. Instead of that, just get the credentials map in setConfig
This commit is contained in:
parent
4e9f8a3c3e
commit
8a5f5438ff
2 changed files with 7 additions and 25 deletions
|
|
@ -31,8 +31,6 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
||||||
*/
|
*/
|
||||||
public static array $credentialsMap = [];
|
public static array $credentialsMap = [];
|
||||||
|
|
||||||
public static string|null $broadcaster = null;
|
|
||||||
|
|
||||||
protected array $originalConfig = [];
|
protected array $originalConfig = [];
|
||||||
protected BroadcastManager|null $originalBroadcastManager = null;
|
protected BroadcastManager|null $originalBroadcastManager = null;
|
||||||
protected BroadcasterContract|null $originalBroadcaster = null;
|
protected BroadcasterContract|null $originalBroadcaster = null;
|
||||||
|
|
@ -59,10 +57,7 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected Repository $config,
|
protected Repository $config,
|
||||||
protected Application $app
|
protected Application $app
|
||||||
) {
|
) {}
|
||||||
static::$broadcaster ??= $config->get('broadcasting.default');
|
|
||||||
static::$credentialsMap = array_merge(static::$mapPresets[static::$broadcaster] ?? [], static::$credentialsMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function bootstrap(Tenant $tenant): void
|
public function bootstrap(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +142,12 @@ class BroadcastingConfigBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
protected function setConfig(Tenant $tenant): void
|
protected function setConfig(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
foreach (static::$credentialsMap as $configKey => $storageKey) {
|
$credentialsMap = array_merge(
|
||||||
|
static::$mapPresets[$this->config->get('broadcasting.default')] ?? [],
|
||||||
|
static::$credentialsMap,
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($credentialsMap as $configKey => $storageKey) {
|
||||||
$override = $tenant->$storageKey;
|
$override = $tenant->$storageKey;
|
||||||
|
|
||||||
if (array_key_exists($storageKey, $tenant->getAttributes())) {
|
if (array_key_exists($storageKey, $tenant->getAttributes())) {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ use Illuminate\Support\Facades\Broadcast;
|
||||||
use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
|
use Illuminate\Contracts\Broadcasting\Broadcaster as BroadcasterContract;
|
||||||
|
|
||||||
afterEach($cleanup = function () {
|
afterEach($cleanup = function () {
|
||||||
BroadcastingConfigBootstrapper::$broadcaster = null;
|
|
||||||
BroadcastingConfigBootstrapper::$credentialsMap = [];
|
BroadcastingConfigBootstrapper::$credentialsMap = [];
|
||||||
BroadcastingConfigBootstrapper::$mapPresets = [
|
BroadcastingConfigBootstrapper::$mapPresets = [
|
||||||
'pusher' => [
|
'pusher' => [
|
||||||
|
|
@ -351,20 +350,3 @@ test('initializing tenancy does not fail when the broadcaster does not extend th
|
||||||
->not()->toBe($centralBroadcaster);
|
->not()->toBe($centralBroadcaster);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setting the broadcaster property overrides which map preset is used', function () {
|
|
||||||
config([
|
|
||||||
'tenancy.bootstrappers' => [BroadcastingConfigBootstrapper::class],
|
|
||||||
'broadcasting.default' => 'testing',
|
|
||||||
'broadcasting.connections.testing.driver' => 'testing',
|
|
||||||
'broadcasting.connections.pusher.key' => 'central_key',
|
|
||||||
]);
|
|
||||||
|
|
||||||
app(BroadcastManager::class)->extend('testing', fn () => new TestingBroadcaster('testing'));
|
|
||||||
|
|
||||||
// Use the pusher preset even though the default connection isn't pusher
|
|
||||||
BroadcastingConfigBootstrapper::$broadcaster = 'pusher';
|
|
||||||
|
|
||||||
tenancy()->initialize(Tenant::create(['pusher_key' => 'tenant_key']));
|
|
||||||
|
|
||||||
expect(config('broadcasting.connections.pusher.key'))->toBe('tenant_key');
|
|
||||||
});
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue