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

Add support for nested tenant config override (#920)

* feat: add support for nested tenant config override

* test: ensure nested tenant values are mapped
This commit is contained in:
George Bishop 2022-08-21 15:43:01 +01:00 committed by GitHub
parent 747c192979
commit 1ea3cefa1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Features;
use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Contracts\Feature; use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Contracts\Tenant;
@ -45,7 +46,7 @@ class TenantConfig implements Feature
{ {
/** @var Tenant|Model $tenant */ /** @var Tenant|Model $tenant */
foreach (static::$storageToConfigMap as $storageKey => $configKey) { foreach (static::$storageToConfigMap as $storageKey => $configKey) {
$override = $tenant->getAttribute($storageKey); $override = Arr::get($tenant, $storageKey);
if (! is_null($override)) { if (! is_null($override)) {
if (is_array($configKey)) { if (is_array($configKey)) {

View file

@ -22,6 +22,30 @@ class TenantConfigTest extends TestCase
parent::tearDown(); parent::tearDown();
} }
/** @test */
public function nested_tenant_values_are_merged()
{
$this->assertSame(null, config('whitelabel.theme'));
config([
'tenancy.features' => [TenantConfig::class],
'tenancy.bootstrappers' => [],
]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
TenantConfig::$storageToConfigMap = [
'whitelabel.config.theme' => 'whitelabel.theme',
];
$tenant = Tenant::create([
'whitelabel' => ['config' => ['theme' => 'dark']],
]);
tenancy()->initialize($tenant);
$this->assertSame('dark', config('whitelabel.theme'));
tenancy()->end();
}
/** @test */ /** @test */
public function config_is_merged_and_removed() public function config_is_merged_and_removed()
{ {