1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 13:34:04 +00:00

TenantConfig first draft

This commit is contained in:
Samuel Štancl 2019-09-27 20:56:42 +02:00
parent 3d1ceadf34
commit 72d16d8efd

View file

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Features;
use Illuminate\Foundation\Application;
use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\TenantManager;
class TenantConfig implements Feature
{
/** @var Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function bootstrap(TenantManager $tenantManager): void
{
$tenantManager->eventListener('bootstrapped', function (TenantManager $manager) {
$this->setTenantConfig($manager->getTenant());
});
$tenantManager->eventListener('ended', function () {
$this->unsetTenantConfig();
});
}
public function setTenantConfig(Tenant $tenant): void
{
foreach($this->getStorageToConfigMap() as $storageKey => $configKey) {
$this->app['config'][$configKey] = $tenant->get($storageKey);
}
}
public function getStorageToConfigMap(): array
{
return $this->app['config']['tenancy.storage_to_config_map'] ?? [];
}
}