mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 03:14:03 +00:00
Improve closure overrides
This commit is contained in:
parent
0b3f6987c3
commit
f878aaf4e4
2 changed files with 9 additions and 7 deletions
|
|
@ -120,7 +120,9 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($override instanceof Closure) {
|
} elseif ($override instanceof Closure) {
|
||||||
$override($this->config, $tenant);
|
$channelConfigKey = "logging.channels.{$channel}";
|
||||||
|
|
||||||
|
$this->config->set($channelConfigKey, $override($this->config->get($channelConfigKey), $tenant));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,8 @@ test('channel overrides work correctly with both arrays and closures', function
|
||||||
// Test both array mapping and closure-based overrides
|
// Test both array mapping and closure-based overrides
|
||||||
LogTenancyBootstrapper::$channelOverrides = [
|
LogTenancyBootstrapper::$channelOverrides = [
|
||||||
'slack' => ['url' => 'webhookUrl'], // slack.url will be mapped to $tenant->webhookUrl
|
'slack' => ['url' => 'webhookUrl'], // slack.url will be mapped to $tenant->webhookUrl
|
||||||
'single' => function ($config, $tenant) {
|
'single' => function (array $channel, Tenant $tenant) {
|
||||||
$config->set('logging.channels.single.path', storage_path("logs/override-{$tenant->id}.log"));
|
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -155,8 +155,8 @@ test('channel overrides take precedence over the default storage path channel up
|
||||||
$tenant = Tenant::create(['id' => 'tenant1']);
|
$tenant = Tenant::create(['id' => 'tenant1']);
|
||||||
|
|
||||||
LogTenancyBootstrapper::$channelOverrides = [
|
LogTenancyBootstrapper::$channelOverrides = [
|
||||||
'single' => function ($config, $tenant) {
|
'single' => function (array $channel, Tenant $tenant) {
|
||||||
$config->set('logging.channels.single.path', storage_path("logs/override-{$tenant->id}.log"));
|
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -261,9 +261,9 @@ test('logs are written to tenant-specific files and do not leak between contexts
|
||||||
$tenant = Tenant::create(['id' => 'override-tenant']);
|
$tenant = Tenant::create(['id' => 'override-tenant']);
|
||||||
|
|
||||||
LogTenancyBootstrapper::$channelOverrides = [
|
LogTenancyBootstrapper::$channelOverrides = [
|
||||||
'single' => function ($config, $tenant) {
|
'single' => function (array $channel, Tenant $tenant) {
|
||||||
// The tenant log path will be set to storage/tenantoverride-tenant/logs/custom-override-tenant.log
|
// The tenant log path will be set to storage/tenantoverride-tenant/logs/custom-override-tenant.log
|
||||||
$config->set('logging.channels.single.path', storage_path("logs/custom-{$tenant->id}.log"));
|
return array_merge($channel, ['path' => storage_path("logs/custom-{$tenant->id}.log")]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue