refactor: mail interfaces
All checks were successful
Build Test / build (pull_request) Successful in 12s
JS Unit Tests / test (pull_request) Successful in 11s
PHP Unit Tests / test (pull_request) Successful in 39s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-05-14 22:54:51 -04:00
parent d6005246dc
commit f3c882454d
24 changed files with 583 additions and 962 deletions

View File

@@ -10,6 +10,11 @@ declare(strict_types=1);
namespace KTXF\Resource\Provider\Node;
use DateTimeImmutable;
use KTXF\Resource\Identifier\CollectionIdentifier;
use KTXF\Resource\Identifier\CollectionIdentifierInterface;
use KTXF\Resource\Identifier\EntityIdentifierInterface;
use KTXF\Resource\Identifier\ResourceIdentifier;
use KTXF\Resource\Identifier\ServiceIdentifier;
/**
* Abstract Node Base Class
@@ -23,6 +28,7 @@ abstract class NodeBaseAbstract implements NodeBaseInterface {
/**
* Internal data storage
*/
protected string $type = 'resource.node';
protected array $data = [];
public function __construct(
@@ -30,87 +36,96 @@ abstract class NodeBaseAbstract implements NodeBaseInterface {
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,
static::PROPERTY_TYPE => $this->type,
static::PROPERTY_PROVIDER => $this->provider,
static::PROPERTY_SERVICE => $this->service,
static::PROPERTY_COLLECTION => null,
static::PROPERTY_IDENTIFIER => null,
static::PROPERTY_SIGNATURE => null,
static::PROPERTY_CREATED => null,
static::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 isset($this->data[static::JSON_PROPERTY_SIGNATURE])
? (string)$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();
$data['provider'] = new ResourceIdentifier($this->data[static::PROPERTY_PROVIDER]);
$data['service'] = new ServiceIdentifier($this->data[static::PROPERTY_PROVIDER], $this->data[static::PROPERTY_SERVICE]);
$data['collection'] = isset($this->data[static::PROPERTY_COLLECTION])
? new CollectionIdentifier($this->data[static::PROPERTY_PROVIDER], $this->data[static::PROPERTY_SERVICE], $this->data[static::PROPERTY_COLLECTION])
: null;
$data['identifier'] = $this->nodeIdentifier();
$data[static::PROPERTY_PROPERTIES] = $this->getProperties()->jsonSerialize();
return $data;
}
abstract protected function nodeIdentifier(): CollectionIdentifierInterface|EntityIdentifierInterface|null;
/**
* @inheritDoc
*/
public function type(): string {
return $this->data[static::PROPERTY_TYPE];
}
/**
* @inheritDoc
*/
public function provider(): string {
return $this->data[static::PROPERTY_PROVIDER];
}
/**
* @inheritDoc
*/
public function service(): string|int {
return $this->data[static::PROPERTY_SERVICE];
}
/**
* @inheritDoc
*/
public function collection(): string|int|null {
return $this->data[static::PROPERTY_COLLECTION] ?? null;
}
/**
* @inheritDoc
*/
public function identifier(): string|int|null {
return $this->data[static::PROPERTY_IDENTIFIER] ?? null;
}
/**
* @inheritDoc
*/
public function signature(): string|null {
return isset($this->data[static::PROPERTY_SIGNATURE])
? (string)$this->data[static::PROPERTY_SIGNATURE]
: null;
}
/**
* @inheritDoc
*/
public function created(): DateTimeImmutable|null {
return isset($this->data[static::PROPERTY_CREATED])
? new DateTimeImmutable($this->data[static::PROPERTY_CREATED])
: null;
}
/**
* @inheritDoc
*/
public function modified(): DateTimeImmutable|null {
return isset($this->data[static::PROPERTY_MODIFIED])
? new DateTimeImmutable($this->data[static::PROPERTY_MODIFIED])
: null;
}
/**
* @inheritDoc
*/

View File

@@ -19,15 +19,15 @@ use KTXF\Json\JsonSerializable;
*/
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';
public const PROPERTY_TYPE = 'resource.node';
public const PROPERTY_PROVIDER = 'provider';
public const PROPERTY_SERVICE = 'service';
public const PROPERTY_COLLECTION = 'collection';
public const PROPERTY_IDENTIFIER = 'identifier';
public const PROPERTY_SIGNATURE = 'signature';
public const PROPERTY_CREATED = 'created';
public const PROPERTY_MODIFIED = 'modified';
public const PROPERTY_PROPERTIES = 'properties';
/**
* Node type

View File

@@ -28,56 +28,56 @@ abstract class NodeMutableAbstract extends NodeBaseAbstract implements NodeMutab
$this->data = [];
if (isset($data[static::JSON_PROPERTY_COLLECTION])) {
if (!is_string($data[static::JSON_PROPERTY_COLLECTION]) && !is_int($data[static::JSON_PROPERTY_COLLECTION])) {
if (isset($data[static::PROPERTY_COLLECTION])) {
if (!is_string($data[static::PROPERTY_COLLECTION]) && !is_int($data[static::PROPERTY_COLLECTION])) {
throw new \InvalidArgumentException("Collection must be a string or integer");
}
$this->data[static::JSON_PROPERTY_COLLECTION] = $data[static::JSON_PROPERTY_COLLECTION];
$this->data[static::PROPERTY_COLLECTION] = $data[static::PROPERTY_COLLECTION];
} else {
$this->data[static::JSON_PROPERTY_COLLECTION] = null;
$this->data[static::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])) {
if (isset($data[static::PROPERTY_IDENTIFIER])) {
if (!is_string($data[static::PROPERTY_IDENTIFIER]) && !is_int($data[static::PROPERTY_IDENTIFIER])) {
throw new \InvalidArgumentException("Identifier must be a string or integer");
}
$this->data[static::JSON_PROPERTY_IDENTIFIER] = $data[static::JSON_PROPERTY_IDENTIFIER];
$this->data[static::PROPERTY_IDENTIFIER] = $data[static::PROPERTY_IDENTIFIER];
} else {
$this->data[static::JSON_PROPERTY_IDENTIFIER] = null;
$this->data[static::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])) {
if (isset($data[static::PROPERTY_SIGNATURE])) {
if (!is_string($data[static::PROPERTY_SIGNATURE]) && !is_int($data[static::PROPERTY_SIGNATURE])) {
throw new \InvalidArgumentException("Signature must be a string or integer");
}
$this->data[static::JSON_PROPERTY_SIGNATURE] = $data[static::JSON_PROPERTY_SIGNATURE];
$this->data[static::PROPERTY_SIGNATURE] = $data[static::PROPERTY_SIGNATURE];
} else {
$this->data[static::JSON_PROPERTY_SIGNATURE] = null;
$this->data[static::PROPERTY_SIGNATURE] = null;
}
if (isset($data[static::JSON_PROPERTY_CREATED])) {
if (!is_string($data[static::JSON_PROPERTY_CREATED])) {
if (isset($data[static::PROPERTY_CREATED])) {
if (!is_string($data[static::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];
$this->data[static::PROPERTY_CREATED] = $data[static::PROPERTY_CREATED];
} else {
$this->data[static::JSON_PROPERTY_CREATED] = null;
$this->data[static::PROPERTY_CREATED] = null;
}
if (isset($data[static::JSON_PROPERTY_MODIFIED])) {
if (!is_string($data[static::JSON_PROPERTY_MODIFIED])) {
if (isset($data[static::PROPERTY_MODIFIED])) {
if (!is_string($data[static::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];
$this->data[static::PROPERTY_MODIFIED] = $data[static::PROPERTY_MODIFIED];
} else {
$this->data[static::JSON_PROPERTY_MODIFIED] = null;
$this->data[static::PROPERTY_MODIFIED] = null;
}
if (isset($data[static::JSON_PROPERTY_PROPERTIES])) {
if (!is_array($data[static::JSON_PROPERTY_PROPERTIES])) {
if (isset($data[static::PROPERTY_PROPERTIES])) {
if (!is_array($data[static::PROPERTY_PROPERTIES])) {
throw new \InvalidArgumentException("Properties must be an array");
}
$this->getProperties()->jsonDeserialize($data[static::JSON_PROPERTY_PROPERTIES]);
$this->getProperties()->jsonDeserialize($data[static::PROPERTY_PROPERTIES]);
}
return $this;

View File

@@ -18,16 +18,17 @@ namespace KTXF\Resource\Provider\Node;
*/
abstract class NodePropertiesBaseAbstract implements NodePropertiesBaseInterface {
protected string $type = 'resource.data';
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::PROPERTY_TYPE])) {
$data[static::PROPERTY_TYPE] = $this->type;
}
if (!isset($data[static::JSON_PROPERTY_SCHEMA])) {
$data[static::JSON_PROPERTY_SCHEMA] = 1;
if (!isset($data[static::PROPERTY_SCHEMA])) {
$data[static::PROPERTY_SCHEMA] = 1;
}
$this->data = $data;
@@ -44,14 +45,14 @@ abstract class NodePropertiesBaseAbstract implements NodePropertiesBaseInterface
* @inheritDoc
*/
public function type(): string {
return $this->data[static::JSON_PROPERTY_TYPE];
return $this->data[static::PROPERTY_TYPE];
}
/**
* @inheritDoc
*/
public function schema(): int {
return $this->data[static::JSON_PROPERTY_SCHEMA];
return $this->data[static::PROPERTY_SCHEMA];
}
}

View File

@@ -18,11 +18,8 @@ use JsonSerializable;
*/
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_SCHEMA = 'schema';
public const PROPERTY_TYPE = '@type';
public const PROPERTY_SCHEMA = 'schema';
/**
* Get resource node properties type

View File

@@ -16,6 +16,4 @@ use KTXF\Json\JsonDeserializable;
*
* @since 2025.05.01
*/
interface NodePropertiesMutableInterface extends NodePropertiesBaseInterface, JsonDeserializable {
}
interface NodePropertiesMutableInterface extends NodePropertiesBaseInterface, JsonDeserializable {}