Initial Version
This commit is contained in:
13
core/lib/Models/Tenant/DomainCollection.php
Normal file
13
core/lib/Models/Tenant/DomainCollection.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Models\Tenant;
|
||||
|
||||
use KTXF\Utile\Collection\CollectionAbstract;
|
||||
|
||||
class DomainCollection extends CollectionAbstract
|
||||
{
|
||||
public function __construct(array $items = [])
|
||||
{
|
||||
parent::__construct($items, CollectionAbstract::TYPE_STRING);
|
||||
}
|
||||
}
|
||||
22
core/lib/Models/Tenant/TenantAuthentication.php
Normal file
22
core/lib/Models/Tenant/TenantAuthentication.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Models\Tenant;
|
||||
|
||||
use KTXF\Json\JsonSerializableObject;
|
||||
|
||||
/**
|
||||
* Tenant Configuration
|
||||
*/
|
||||
class TenantAuthentication extends JsonSerializableObject
|
||||
{
|
||||
protected array $providers = [];
|
||||
protected int $methodsMinimal = 1;
|
||||
|
||||
public function providers(): array {
|
||||
return $this->providers;
|
||||
}
|
||||
|
||||
public function methodsMinimal(): int {
|
||||
return $this->methodsMinimal;
|
||||
}
|
||||
}
|
||||
13
core/lib/Models/Tenant/TenantCollection.php
Normal file
13
core/lib/Models/Tenant/TenantCollection.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Models\Tenant;
|
||||
|
||||
use KTXF\Utile\Collection\CollectionAbstract;
|
||||
|
||||
class TenantCollection extends CollectionAbstract
|
||||
{
|
||||
public function __construct(array $items = [])
|
||||
{
|
||||
parent::__construct($items, TenantObject::class, CollectionAbstract::TYPE_STRING);
|
||||
}
|
||||
}
|
||||
29
core/lib/Models/Tenant/TenantConfiguration.php
Normal file
29
core/lib/Models/Tenant/TenantConfiguration.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Models\Tenant;
|
||||
|
||||
use KTXF\Json\JsonSerializableObject;
|
||||
|
||||
/**
|
||||
* Tenant Configuration
|
||||
*/
|
||||
class TenantConfiguration extends JsonSerializableObject
|
||||
{
|
||||
protected TenantAuthentication $authentication;
|
||||
protected TenantSecurity $security;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->authentication = new TenantAuthentication();
|
||||
$this->security = new TenantSecurity();
|
||||
}
|
||||
|
||||
public function authentication(): TenantAuthentication {
|
||||
return $this->authentication;
|
||||
}
|
||||
|
||||
public function security(): TenantSecurity {
|
||||
return $this->security;
|
||||
}
|
||||
|
||||
}
|
||||
148
core/lib/Models/Tenant/TenantObject.php
Normal file
148
core/lib/Models/Tenant/TenantObject.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
22
core/lib/Models/Tenant/TenantSecurity.php
Normal file
22
core/lib/Models/Tenant/TenantSecurity.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Models\Tenant;
|
||||
|
||||
use KTXF\Json\JsonSerializableObject;
|
||||
|
||||
/**
|
||||
* Tenant Configuration
|
||||
*/
|
||||
class TenantSecurity extends JsonSerializableObject
|
||||
{
|
||||
protected string $code = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->code = uniqid();
|
||||
}
|
||||
|
||||
public function code(): string {
|
||||
return $this->code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user