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)
Bug description
The v4 docs mention that when using
BroadcastingConfigBootstrapperyou can map your own custom tenant values inTenancyServiceProvider::boot, like so:However this doesn't work as
BroadcastingConfigBootstrappermerges$credentialsMapand$mapPresetstogether with$mapPresetsas the second param toarray_merge, causing customisations to keys present in$mapPresetsto be prioritized.tenancy/src/Bootstrappers/BroadcastingConfigBootstrapper.php
Line 57 in e31249d
Steps to reproduce
Set some custom values in
TenancyServiceProvider::boot:Add a
ddat the end ofBroadcastingConfigBootstrapper::__constructObserve that the customisations have been reset back to the presets:
Expected behavior
Values in
$credentialsMapdo not get reverted to the preset values.Note: In my tests swapping the params to
array_mergeindeed fixes the issue. For now I am just overriding$mapPresetsfrombootinstead, but it feels hacky compared to the documented method.Laravel version
13
stancl/tenancy version
4 (dev-master)