mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 11:44:04 +00:00
TenantConfig first draft
This commit is contained in:
parent
3d1ceadf34
commit
72d16d8efd
1 changed files with 44 additions and 0 deletions
44
src/Features/TenantConfig.php
Normal file
44
src/Features/TenantConfig.php
Normal 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'] ?? [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue