149 lines
3.9 KiB
PHP
149 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace KTXC\Models\Tenant;
|
|
|
|
use KTXF\Json\JsonSerializableObject;
|
|
|
|
/**
|
|
* Tenant entity representing a tenant
|
|
*/
|
|
class TenantObject extends JsonSerializableObject
|
|
{
|
|
private ?string $id = null;
|
|
private ?string $identifier = null;
|
|
private bool $enabled = false;
|
|
private ?string $label = null;
|
|
private ?string $description = null;
|
|
private ?DomainCollection $domains = null;
|
|
private ?TenantConfiguration $configuration = null;
|
|
|
|
/**
|
|
* Deserialize from associative array.
|
|
*/
|
|
public function jsonDeserialize(array|string $data): static
|
|
{
|
|
if (is_string($data)) {
|
|
$data = json_decode($data, true);
|
|
}
|
|
// Map only if key exists to avoid notices and allow partial input
|
|
if (array_key_exists('_id', $data)) $this->id = $data['_id'] !== null ? (string)$data['_id'] : null;
|
|
elseif (array_key_exists('id', $data)) $this->id = $data['id'] !== null ? (string)$data['id'] : null;
|
|
if (array_key_exists('identifier', $data)) $this->identifier = $data['identifier'] !== null ? (string)$data['identifier'] : null;
|
|
if (array_key_exists('enabled', $data)) $this->enabled = $data['enabled'] !== null ? (bool)$data['enabled'] : null;
|
|
if (array_key_exists('label', $data)) $this->label = $data['label'] !== null ? (string)$data['label'] : null;
|
|
if (array_key_exists('description', $data)) $this->description = $data['description'] !== null ? (string)$data['description'] : null;
|
|
if (array_key_exists('domains', $data)) {
|
|
$this->domains = (new DomainCollection((array)$data['domains']));
|
|
}
|
|
if (array_key_exists('configuration', $data)) {
|
|
$this->configuration = (new TenantConfiguration)->jsonDeserialize($data['configuration']);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Serialize to JSON-friendly structure.
|
|
*/
|
|
public function jsonSerialize(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'identifier' => $this->identifier,
|
|
'enabled' => $this->enabled,
|
|
'label' => $this->label,
|
|
'description' => $this->description,
|
|
'domains' => $this->domains,
|
|
'configuration' => $this->configuration,
|
|
];
|
|
}
|
|
|
|
public function getId(): ?string
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setId(string $value): self
|
|
{
|
|
$this->id = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getIdentifier(): ?string
|
|
{
|
|
return $this->identifier;
|
|
}
|
|
|
|
public function setIdentifier(string $value): self
|
|
{
|
|
$this->identifier = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getEnabled(): bool
|
|
{
|
|
return $this->enabled;
|
|
}
|
|
|
|
public function setEnabled(bool $value): self
|
|
{
|
|
$this->enabled = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getLabel(): ?string
|
|
{
|
|
return $this->label;
|
|
}
|
|
|
|
public function setLabel(string $value): self
|
|
{
|
|
$this->label = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(string $value): self
|
|
{
|
|
$this->description = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getDomains(): ?DomainCollection
|
|
{
|
|
return $this->domains;
|
|
}
|
|
|
|
public function setDomains(DomainCollection $value): self
|
|
{
|
|
$this->domains = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getConfiguration(): TenantConfiguration
|
|
{
|
|
return $this->configuration;
|
|
}
|
|
|
|
public function setConfiguration(TenantConfiguration $value): self
|
|
{
|
|
$this->configuration = $value;
|
|
return $this;
|
|
}
|
|
|
|
public function getSettings(): array
|
|
{
|
|
return $this->configuration['settings'] ?? [];
|
|
}
|
|
|
|
public function setSettings(array $value): self
|
|
{
|
|
$this->configuration['settings'] = $value;
|
|
return $this;
|
|
}
|
|
|
|
}
|