mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 20:54:02 +00:00
Support channel overrides using dot notation
This commit is contained in:
parent
9660faf2f9
commit
221a9950c2
2 changed files with 7 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ use Illuminate\Contracts\Config\Repository as Config;
|
||||||
use Illuminate\Log\LogManager;
|
use Illuminate\Log\LogManager;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This bootstrapper makes it possible to configure tenant-specific logging.
|
* This bootstrapper makes it possible to configure tenant-specific logging.
|
||||||
|
|
@ -128,7 +129,7 @@ class LogTenancyBootstrapper implements TenancyBootstrapper
|
||||||
// If the tenant attribute is null,
|
// If the tenant attribute is null,
|
||||||
// the override is ignored and the channel config key's value remains unchanged.
|
// the override is ignored and the channel config key's value remains unchanged.
|
||||||
foreach ($override as $configKey => $tenantAttributeName) {
|
foreach ($override as $configKey => $tenantAttributeName) {
|
||||||
$tenantAttribute = $tenant->getAttribute($tenantAttributeName);
|
$tenantAttribute = Arr::get($tenant, $tenantAttributeName);
|
||||||
|
|
||||||
if ($tenantAttribute !== null) {
|
if ($tenantAttribute !== null) {
|
||||||
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenantAttribute);
|
$this->config->set("logging.channels.{$channel}.{$configKey}", $tenantAttribute);
|
||||||
|
|
|
||||||
|
|
@ -366,11 +366,12 @@ test('slack channel uses correct webhook urls', function () {
|
||||||
expect($thrown)->toBeTrue();
|
expect($thrown)->toBeTrue();
|
||||||
};
|
};
|
||||||
|
|
||||||
$tenant1 = Tenant::create(['id' => 'tenant1', 'slackUrl' => 'tenant1-webhook']);
|
$tenant1 = Tenant::create(['id' => 'tenant1', 'logging' => ['slackUrl' => 'tenant1-webhook']]);
|
||||||
$tenant2 = Tenant::create(['id' => 'tenant2', 'slackUrl' => 'tenant2-webhook']);
|
$tenant2 = Tenant::create(['id' => 'tenant2', 'logging' => ['slackUrl' => 'tenant2-webhook']]);
|
||||||
|
|
||||||
|
// Attribute mapping using nested attributes (dot notation) works
|
||||||
LogTenancyBootstrapper::$channelOverrides = [
|
LogTenancyBootstrapper::$channelOverrides = [
|
||||||
'slack' => ['url' => 'slackUrl'],
|
'slack' => ['url' => 'logging.slackUrl'],
|
||||||
];
|
];
|
||||||
|
|
||||||
// Test central context - should attempt to use central webhook
|
// Test central context - should attempt to use central webhook
|
||||||
|
|
@ -378,7 +379,7 @@ test('slack channel uses correct webhook urls', function () {
|
||||||
|
|
||||||
// Slack channel should attempt to use the tenant-specific webhooks
|
// Slack channel should attempt to use the tenant-specific webhooks
|
||||||
tenancy()->runForMultiple([$tenant1, $tenant2], function (Tenant $tenant) use ($assertWebhook) {
|
tenancy()->runForMultiple([$tenant1, $tenant2], function (Tenant $tenant) use ($assertWebhook) {
|
||||||
$assertWebhook($tenant->slackUrl, $tenant->id);
|
$assertWebhook($tenant->logging['slackUrl'], $tenant->id);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Central context, central webhook should be used again
|
// Central context, central webhook should be used again
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue