1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 17:24:03 +00:00

By default, only override the config if the override tenant property is set (otherwise, just skip the override and keep the default config value)

This commit is contained in:
lukinovec 2025-07-31 15:15:33 +02:00
parent 582243c53f
commit bd44036a9f
2 changed files with 17 additions and 1 deletions

View file

@ -100,7 +100,9 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
if (is_array($override)) { if (is_array($override)) {
// Map tenant properties to channel config keys // Map tenant properties to channel config keys
foreach ($override as $configKey => $tenantProperty) { foreach ($override as $configKey => $tenantProperty) {
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenant->$tenantProperty); if ($tenant->$tenantProperty) {
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenant->$tenantProperty);
}
} }
} elseif ($override instanceof Closure) { } elseif ($override instanceof Closure) {
// Execute custom configuration closure // Execute custom configuration closure

View file

@ -150,6 +150,20 @@ test('channel overrides work correctly with both arrays and closures', function
expect(config('logging.channels.slack.username'))->toBe('Default'); expect(config('logging.channels.slack.username'))->toBe('Default');
}); });
test('channel config keys remains unchanged if the specified tenant override property is not set', function() {
config(['logging.default' => 'slack']);
config(['logging.channels.slack.username' => 'Default username']);
LogTenancyBootstrapper::$channelOverrides = [
'slack' => ['username' => 'nonExistentProperty'], // $tenant->nonExistentProperty
];
tenancy()->initialize(Tenant::create());
// The username should remain unchanged since the tenant property is not set
expect(config('logging.channels.slack.username'))->toBe('Default username');
});
test('channel overrides take precedence over the default storage path channel updating logic', function () { test('channel overrides take precedence over the default storage path channel updating logic', function () {
config(['logging.default' => 'single']); config(['logging.default' => 'single']);