1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 20:34:04 +00:00

Throw exception if override closure doesn't return array

This commit is contained in:
lukinovec 2026-04-13 14:39:42 +02:00
parent cdea112ad5
commit 8fda84fcee
2 changed files with 17 additions and 3 deletions

View file

@ -44,7 +44,9 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
*
* Examples:
* - Array mapping (the default approach): ['slack' => ['url' => 'webhookUrl']] maps $tenant->webhookUrl to slack.url (if $tenant->webhookUrl is not null, otherwise, the override is ignored)
* - Closure: ['slack' => fn (Tenant $tenant, array $channel) => array_merge($channel, ['url' => $tenant->slackUrl])]
* - Closure: ['slack' => fn (Tenant $tenant, array $channel) => array_merge($channel, ['url' => $tenant->slackUrl])] (the closure should return the whole channel's config)
*
* In both cases, the override should be an array.
*/
public static array $channelOverrides = [];
@ -140,7 +142,13 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
} elseif ($override instanceof Closure) {
$channelConfigKey = "logging.channels.{$channel}";
$this->config->set($channelConfigKey, $override($tenant, $this->config->get($channelConfigKey)));
$result = $override($tenant, $this->config->get($channelConfigKey));
if (! is_array($result)) {
throw new \InvalidArgumentException("Channel override closure for '{$channel}' must return an array.");
}
$this->config->set($channelConfigKey, $result);
}
}