32 خطوط
677 B
PHP
32 خطوط
677 B
PHP
<?php
|
|
|
|
namespace App\Modules\Tenancy\Application;
|
|
|
|
use App\Modules\Organizations\Domain\Organization;
|
|
use LogicException;
|
|
|
|
final class TenantContext
|
|
{
|
|
private ?Organization $organization = null;
|
|
|
|
public function set(Organization $organization): void
|
|
{
|
|
$this->organization = $organization;
|
|
}
|
|
|
|
public function organization(): Organization
|
|
{
|
|
return $this->organization ?? throw new LogicException('Tenant context has not been established.');
|
|
}
|
|
|
|
public function id(): string
|
|
{
|
|
return $this->organization()->getKey();
|
|
}
|
|
|
|
public function hasTenant(): bool
|
|
{
|
|
return $this->organization !== null;
|
|
}
|
|
}
|