1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 13:14:05 +00:00
tenancy/src/Tenancy.php
2020-05-10 23:47:11 +02:00

51 lines
1.2 KiB
PHP

<?php
namespace Stancl\Tenancy;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
class Tenancy
{
/** @var Tenant|null */
public $tenant;
/** @var callable|null */
public static $getBootstrappers = null;
/** @var bool */
public $initialized = false;
public function initialize(Tenant $tenant): void
{
if ($this->initialized && $this->tenant->getTenantKey() === $tenant->getTenantKey()) {
return;
}
$this->tenant = $tenant;
$this->initialized = true;
event(new Events\TenancyInitialized($this));
}
public function end(): void
{
$this->initialized = false;
event(new Events\TenancyEnded($this));
$this->tenant = null;
}
/** @return TenancyBootstrapper[] */
public function getBootstrappers(): array
{
// If no callback for getting bootstrappers is set, we just return all of them.
$resolve = static::$getBootstrappers ?? function (Tenant $tenant) {
return array_map('app', config('tenancy.bootstrappers'));
};
return $resolve($this->tenant);
}
}