Skip to content

Modifications to BroadcastingConfigBootstrapper::$credentialsMap are overwritten with values from $mapPresets #1454

@se1exin

Description

@se1exin

Bug description

The v4 docs mention that when using BroadcastingConfigBootstrapper you can map your own custom tenant values in TenancyServiceProvider::boot, like so:

BroadcastingConfigBootstrapper::$credentialsMap[
    'broadcasting.connections.pusher.key'
] = 'pusher_key';

However this doesn't work as BroadcastingConfigBootstrapper merges $credentialsMap and $mapPresets together with $mapPresets as the second param to array_merge, causing customisations to keys present in $mapPresets to be prioritized.

static::$credentialsMap = array_merge(static::$credentialsMap, static::$mapPresets[static::$broadcaster] ?? []);

Steps to reproduce

Set some custom values in TenancyServiceProvider::boot:

BroadcastingConfigBootstrapper::$credentialsMap = [
    'broadcasting.connections.reverb.key' => 'slug',
    'broadcasting.connections.reverb.app_id' => 'slug',
    'reverb.apps.0.reverb.key' => 'slug',
    'reverb.apps.0.reverb.app_id' => 'slug',
];

Add a dd at the end of BroadcastingConfigBootstrapper::__construct

public function __construct(
        protected Repository $config,
        protected Application $app
    ) {
        static::$broadcaster ??= $config->get('broadcasting.default');
        static::$credentialsMap = array_merge(static::$credentialsMap, static::$mapPresets[static::$broadcaster] ?? []);

        dd(static::$credentialsMap);  // <--- HERE
    }

Observe that the customisations have been reset back to the presets:

array:6 [▼ // vendor/stancl/tenancy/src/Bootstrappers/BroadcastingConfigBootstrapper.php:59
  "broadcasting.connections.reverb.key" => "reverb_key"
  "broadcasting.connections.reverb.app_id" => "reverb_app_id"
  "reverb.apps.0.reverb.key" => "slug"
  "reverb.apps.0.reverb.app_id" => "slug"
  "broadcasting.connections.reverb.secret" => "reverb_secret"
  "broadcasting.connections.reverb.options.cluster" => "reverb_cluster"
]

Expected behavior

Values in $credentialsMap do not get reverted to the preset values.

Note: In my tests swapping the params to array_merge indeed fixes the issue. For now I am just overriding $mapPresets from boot instead, but it feels hacky compared to the documented method.

Laravel version

13

stancl/tenancy version

4 (dev-master)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions