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

DatabaseManager WIP

This commit is contained in:
Samuel Štancl 2019-09-05 19:26:29 +02:00
parent 798df54d76
commit 41d8bb7e09
8 changed files with 125 additions and 78 deletions

View file

@ -4,8 +4,32 @@ declare(strict_types=1);
namespace Stancl\Tenancy;
final class TenantManager
use Illuminate\Foundation\Application;
/**
* @internal Class is subject to breaking changes in minor and patch versions.
*/
class TenantManagerv2
{
/**
* The current tenant.
*
* @var Tenant
*/
public $tenant;
/** @var Application */
private $app;
/** @var Contracts\StorageDriver */
private $storage;
public function __construct(Application $app, Contracts\StorageDriver $storage)
{
$this->app = $app;
$this->storage = $storage;
}
public function addTenant(Tenant $tenant): self
{
$this->storage->addTenant($tenant);
@ -19,4 +43,38 @@ final class TenantManager
return $this;
}
public function initializeTenancy(Tenant $tenant): self
{
$this->bootstrapTenancy($tenant);
$this->setTenant($tenant);
return $this;
}
public function bootstrapTenancy(Tenant $tenant): self
{
foreach($this->tenancyBootstrappers() as $bootstrapper) {
$bootstrapper::start($tenant);
}
return $this;
}
public function setTenant(Tenant $tenant): self
{
$this->app->instance(Tenant::class, $tenant);
return $this;
}
/**
* Return a list of TenancyBoostrappers.
*
* @return Contracts\TenancyBootstrapper[]
*/
public function tenancyBootstrappers(): array
{
return config('tenancy.bootstrappers');
}
}