mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:24:04 +00:00
Swap closure param order, add/update comments
This commit is contained in:
parent
b36f3ce4ee
commit
108e0d1363
2 changed files with 8 additions and 8 deletions
|
|
@ -37,7 +37,7 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
|
||||||
*
|
*
|
||||||
* Examples:
|
* 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)
|
* - 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 ($config, $tenant) => $config->set('logging.channels.slack.url', $tenant->slackUrl)]
|
* - Closure: ['slack' => fn (Tenant $tenant, array $channel) => array_merge($channel, ['url' => $tenant->slackUrl])]
|
||||||
*/
|
*/
|
||||||
public static array $channelOverrides = [];
|
public static array $channelOverrides = [];
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
|
||||||
$this->overrideChannelConfig($channel, static::$channelOverrides[$channel], $tenant);
|
$this->overrideChannelConfig($channel, static::$channelOverrides[$channel], $tenant);
|
||||||
} elseif (in_array($channel, static::$storagePathChannels)) {
|
} elseif (in_array($channel, static::$storagePathChannels)) {
|
||||||
// Set storage path channels to use tenant-specific directory (default behavior)
|
// Set storage path channels to use tenant-specific directory (default behavior)
|
||||||
// The tenant log will be located at e.g. "storage/tenant{$tenantKey}/logs/laravel.log"
|
// The tenant log will be located at e.g. "storage/tenant{$tenantKey}/logs/laravel.log" (assuming FilesystemTenancyBootstrapper is used before this bootstrapper)
|
||||||
$this->config->set("logging.channels.{$channel}.path", storage_path('logs/laravel.log'));
|
$this->config->set("logging.channels.{$channel}.path", storage_path('logs/laravel.log'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +122,7 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
|
||||||
} elseif ($override instanceof Closure) {
|
} elseif ($override instanceof Closure) {
|
||||||
$channelConfigKey = "logging.channels.{$channel}";
|
$channelConfigKey = "logging.channels.{$channel}";
|
||||||
|
|
||||||
$this->config->set($channelConfigKey, $override($this->config->get($channelConfigKey), $tenant));
|
$this->config->set($channelConfigKey, $override($tenant, $this->config->get($channelConfigKey)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
config([
|
config([
|
||||||
'tenancy.bootstrappers' => [
|
'tenancy.bootstrappers' => [
|
||||||
// FilesystemTenancyBootstrapper needed for storage path channels (added in tests that check the storage path channel logic)
|
// FilesystemTenancyBootstrapper needed for LogTenancyBootstrapper to work with storage path channels BY DEFAULT (note that this can be completely overridden)
|
||||||
LogTenancyBootstrapper::class,
|
LogTenancyBootstrapper::class,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
@ -33,7 +33,7 @@ afterEach(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('storage path channels get tenant-specific paths by default', function () {
|
test('storage path channels get tenant-specific paths by default', function () {
|
||||||
// Note that for LogTenancyBootstrapper to change the paths correctly,
|
// Note that for LogTenancyBootstrapper to change the paths correctly by default,
|
||||||
// the bootstrapper MUST run after FilesystemTenancyBootstrapper.
|
// the bootstrapper MUST run after FilesystemTenancyBootstrapper.
|
||||||
config([
|
config([
|
||||||
'tenancy.bootstrappers' => [
|
'tenancy.bootstrappers' => [
|
||||||
|
|
@ -113,7 +113,7 @@ 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 (array $channel, Tenant $tenant) {
|
'single' => function (Tenant $tenant, array $channel) {
|
||||||
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -155,7 +155,7 @@ 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 (array $channel, Tenant $tenant) {
|
'single' => function (Tenant $tenant, array $channel) {
|
||||||
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -261,7 +261,7 @@ 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 (array $channel, Tenant $tenant) {
|
'single' => function (Tenant $tenant, array $channel) {
|
||||||
// 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
|
||||||
return array_merge($channel, ['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