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

Fix initialize() method

This commit is contained in:
Samuel Štancl 2020-09-04 12:42:08 +02:00
parent 375380cc7e
commit 2cd00a5b77

View file

@ -31,6 +31,16 @@ class Tenancy
*/ */
public function initialize($tenant): void public function initialize($tenant): void
{ {
if (! is_object($tenant)) {
$tenant = $tenant;
$tenantId = $tenant;
$tenant = $this->find($tenantId);
if (! $tenant) {
throw new TenantCountNotBeIdentifiedById($tenantId);
}
}
if ($this->initialized && $this->tenant->getTenantKey() === $tenant->getTenantKey()) { if ($this->initialized && $this->tenant->getTenantKey() === $tenant->getTenantKey()) {
return; return;
} }
@ -40,18 +50,7 @@ class Tenancy
$this->end(); $this->end();
} }
if (is_object($tenant)) { $this->tenant = $tenant;
$this->tenant = $tenant;
} else {
$tenantId = $tenant;
$tenant = $this->find($tenantId);
if (! $tenant) {
throw new TenantCountNotBeIdentifiedById($tenantId);
}
$this->tenant = $tenant;
}
event(new Events\InitializingTenancy($this)); event(new Events\InitializingTenancy($this));