Initial Version

This commit is contained in:
root
2025-12-21 10:09:54 -05:00
commit 4ae6befc7b
422 changed files with 47225 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
use DateTimeImmutable;
/**
* Abstract Node Base Class
*
* Provides common implementation for all resource nodes
*
* @since 2025.05.01
*/
abstract class NodeBaseAbstract implements NodeBaseInterface {
/**
* Internal data storage
*/
protected array $data = [];
public function __construct(
protected readonly string $provider,
protected readonly string|int $service,
) {
$this->data = [
static::JSON_PROPERTY_PROVIDER => $this->provider,
static::JSON_PROPERTY_SERVICE => $this->service,
static::JSON_PROPERTY_COLLECTION => null,
static::JSON_PROPERTY_IDENTIFIER => null,
static::JSON_PROPERTY_SIGNATURE => null,
static::JSON_PROPERTY_CREATED => null,
static::JSON_PROPERTY_MODIFIED => null,
];
}
/**
* @inheritDoc
*/
public function type(): string {
return static::RESOURCE_TYPE;
}
/**
* @inheritDoc
*/
public function provider(): string {
return $this->data[static::JSON_PROPERTY_PROVIDER];
}
/**
* @inheritDoc
*/
public function service(): string|int {
return $this->data[static::JSON_PROPERTY_SERVICE];
}
/**
* @inheritDoc
*/
public function collection(): string|int|null {
return $this->data[static::JSON_PROPERTY_COLLECTION] ?? null;
}
/**
* @inheritDoc
*/
public function identifier(): string|int|null {
return $this->data[static::JSON_PROPERTY_IDENTIFIER] ?? null;
}
/**
* @inheritDoc
*/
public function signature(): string|null {
return $this->data[static::JSON_PROPERTY_SIGNATURE] ?? null;
}
/**
* @inheritDoc
*/
public function created(): DateTimeImmutable|null {
return isset($this->data[static::JSON_PROPERTY_CREATED])
? new DateTimeImmutable($this->data[static::JSON_PROPERTY_CREATED])
: null;
}
/**
* @inheritDoc
*/
public function modified(): DateTimeImmutable|null {
return isset($this->data[static::JSON_PROPERTY_MODIFIED])
? new DateTimeImmutable($this->data[static::JSON_PROPERTY_MODIFIED])
: null;
}
/**
* @inheritDoc
*/
public function jsonSerialize(): array {
$data = $this->data;
$data[static::JSON_PROPERTY_PROPERTIES] = $this->getProperties()->jsonSerialize();
return $data;
}
/**
* @inheritDoc
*/
abstract public function getProperties(): NodePropertiesBaseInterface;
}

View File

@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
use DateTimeImmutable;
use KTXF\Json\JsonSerializable;
/**
* Resource Node Read Interface
*
* @since 2025.05.01
*/
interface NodeBaseInterface extends JsonSerializable {
public const RESOURCE_TYPE = 'resource.node';
public const JSON_PROPERTY_PROVIDER = 'provider';
public const JSON_PROPERTY_SERVICE = 'service';
public const JSON_PROPERTY_COLLECTION = 'collection';
public const JSON_PROPERTY_IDENTIFIER = 'identifier';
public const JSON_PROPERTY_SIGNATURE = 'signature';
public const JSON_PROPERTY_CREATED = 'created';
public const JSON_PROPERTY_MODIFIED = 'modified';
public const JSON_PROPERTY_PROPERTIES = 'properties';
/**
* Node type
*
* @since 2025.05.01
*/
public function type(): string;
/**
* Provider identifier
*
* @since 2025.05.01
*/
public function provider(): string;
/**
* Service identifier
*
* @since 2025.05.01
*/
public function service(): string|int;
/**
* Collection identifier
*
* @since 2025.05.01
*/
public function collection(): string|int|null;
/**
* Node identifier
*
* @since 2025.05.01
*/
public function identifier(): string|int|null;
/**
* Node signature/sync token
*
* @since 2025.05.01
*/
public function signature(): string|null;
/**
* Node creation date
*
* @since 2025.05.01
*/
public function created(): DateTimeImmutable|null;
/**
* Node modification date
*
* @since 2025.05.01
*/
public function modified(): DateTimeImmutable|null;
/**
* Get the node properties
*
* @since 2025.05.01
*/
public function getProperties(): NodePropertiesBaseInterface|NodePropertiesMutableInterface;
}

View File

@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
/**
* Abstract Node Mutable Class
*
* Provides common implementation for mutable resource nodes
*
* @since 2025.05.01
*/
abstract class NodeMutableAbstract extends NodeBaseAbstract implements NodeMutableInterface {
/**
* @inheritDoc
*/
public function jsonDeserialize(array|string $data): static {
if (is_string($data)) {
$data = json_decode($data, true);
}
$this->data = [];
if (isset($data[static::JSON_PROPERTY_COLLECTION])) {
if (!is_string($data[static::JSON_PROPERTY_COLLECTION]) && !is_int($data[static::JSON_PROPERTY_COLLECTION])) {
throw new \InvalidArgumentException("Collection must be a string or integer");
}
$this->data[static::JSON_PROPERTY_COLLECTION] = $data[static::JSON_PROPERTY_COLLECTION];
} else {
$this->data[static::JSON_PROPERTY_COLLECTION] = null;
}
if (isset($data[static::JSON_PROPERTY_IDENTIFIER])) {
if (!is_string($data[static::JSON_PROPERTY_IDENTIFIER]) && !is_int($data[static::JSON_PROPERTY_IDENTIFIER])) {
throw new \InvalidArgumentException("Identifier must be a string or integer");
}
$this->data[static::JSON_PROPERTY_IDENTIFIER] = $data[static::JSON_PROPERTY_IDENTIFIER];
} else {
$this->data[static::JSON_PROPERTY_IDENTIFIER] = null;
}
if (isset($data[static::JSON_PROPERTY_SIGNATURE])) {
if (!is_string($data[static::JSON_PROPERTY_SIGNATURE]) && !is_int($data[static::JSON_PROPERTY_SIGNATURE])) {
throw new \InvalidArgumentException("Signature must be a string or integer");
}
$this->data[static::JSON_PROPERTY_SIGNATURE] = $data[static::JSON_PROPERTY_SIGNATURE];
} else {
$this->data[static::JSON_PROPERTY_SIGNATURE] = null;
}
if (isset($data[static::JSON_PROPERTY_CREATED])) {
if (!is_string($data[static::JSON_PROPERTY_CREATED])) {
throw new \InvalidArgumentException("Created date must be a string in ISO 8601 format");
}
$this->data[static::JSON_PROPERTY_CREATED] = $data[static::JSON_PROPERTY_CREATED];
} else {
$this->data[static::JSON_PROPERTY_CREATED] = null;
}
if (isset($data[static::JSON_PROPERTY_MODIFIED])) {
if (!is_string($data[static::JSON_PROPERTY_MODIFIED])) {
throw new \InvalidArgumentException("Modified date must be a string in ISO 8601 format");
}
$this->data[static::JSON_PROPERTY_MODIFIED] = $data[static::JSON_PROPERTY_MODIFIED];
} else {
$this->data[static::JSON_PROPERTY_MODIFIED] = null;
}
if (isset($data[static::JSON_PROPERTY_PROPERTIES])) {
if (!is_array($data[static::JSON_PROPERTY_PROPERTIES])) {
throw new \InvalidArgumentException("Properties must be an array");
}
$this->getProperties()->jsonDeserialize($data[static::JSON_PROPERTY_PROPERTIES]);
}
return $this;
}
/**
* @inheritDoc
*/
abstract public function getProperties(): NodePropertiesMutableInterface;
/**
* @inheritDoc
*/
abstract public function setProperties(NodePropertiesMutableInterface $value): static;
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
use KTXF\Json\JsonDeserializable;
/**
* Node Mutable Write Interface
*
* @since 2025.05.01
*/
interface NodeMutableInterface extends NodeBaseInterface, JsonDeserializable {
/**
* Get the node properties
*
* @since 2025.05.01
*/
public function getProperties(): NodePropertiesMutableInterface;
/**
* Sets the node properties
*
* @since 2025.05.01
*/
public function setProperties(NodePropertiesMutableInterface $value): static;
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
/**
* Abstract Node Properties Base Class
*
* Provides common implementation for node properties
*
* @since 2025.05.01
*/
abstract class NodePropertiesBaseAbstract implements NodePropertiesBaseInterface {
protected array $data = [];
public function __construct(array $data) {
if (!isset($data[static::JSON_PROPERTY_TYPE])) {
$data[static::JSON_PROPERTY_TYPE] = static::JSON_TYPE;
}
if (!isset($data[static::JSON_PROPERTY_VERSION])) {
$data[static::JSON_PROPERTY_VERSION] = 1;
}
$this->data = $data;
}
/**
* @inheritDoc
*/
public function jsonSerialize(): array {
return $this->data;
}
/**
* @inheritDoc
*/
public function type(): string {
return $this->data[static::JSON_PROPERTY_TYPE];
}
/**
* @inheritDoc
*/
public function version(): int {
return $this->data[static::JSON_PROPERTY_VERSION];
}
}

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
use JsonSerializable;
/**
* Resource Node Properties Read Interface
*
* @since 2025.05.01
*/
interface NodePropertiesBaseInterface extends JsonSerializable {
public const RESOURCE_TYPE = 'resource.data';
public const JSON_TYPE = 'resource.data';
public const JSON_PROPERTY_TYPE = '@type';
public const JSON_PROPERTY_VERSION = 'version';
/**
* Get resource node properties type
*/
public function type(): string;
/**
* Get resource node properties version
*/
public function version(): int;
}

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
/**
* Abstract Node Properties Mutable Class
*
* Provides common implementation for mutable node properties
*
* @since 2025.05.01
*/
abstract class NodePropertiesMutableAbstract extends NodePropertiesBaseAbstract implements NodePropertiesMutableInterface {
/**
* @inheritDoc
*/
public function jsonDeserialize(array|string $data): static {
if (is_string($data)) {
$data = json_decode($data, true);
}
$this->data = $data;
return $this;
}
}

View File

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
use KTXF\Json\JsonDeserializable;
/**
* Resource Node Properties Mutable Interface
*
* @since 2025.05.01
*/
interface NodePropertiesMutableInterface extends NodePropertiesBaseInterface, JsonDeserializable {
}