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,45 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Delta;
use KTXF\Json\JsonSerializable;
class Delta implements JsonSerializable {
public function __construct(
public ?DeltaCollection $additions = null,
public ?DeltaCollection $modifications = null,
public ?DeltaCollection $deletions = null,
public ?string $signature = null,
) {
if ($this->additions === null) {
$this->additions = new DeltaCollection;
}
if ($this->modifications === null) {
$this->modifications = new DeltaCollection;
}
if ($this->deletions === null) {
$this->deletions = new DeltaCollection;
}
if ($this->signature === null) {
$this->signature = '';
}
}
public function jsonSerialize(): array {
return [
'signature' => $this->signature,
'additions' => $this->additions,
'modifications' => $this->modifications,
'deletions' => $this->deletions,
];
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Delta;
use KTXF\Json\JsonSerializableCollection;
class DeltaCollection extends JsonSerializableCollection {
public function __construct($data = []) {
parent::__construct($data, self::TYPE_STRING);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace KTXF\Resource\Exceptions;
use Exception;
/**
* Exemption for unauthorized access
*/
class InvalidParameterException extends Exception {
/**
* @param string $message The exception message
* @param int $code The exception code
* @param Exception|null $previous The previous exception
*/
public function __construct($message = "Invalid Parameter", $code = 0, ?Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace KTXF\Resource\Exceptions;
use Exception;
/**
* Exemption for unauthorized access
*/
class UnauthorizedException extends Exception {
/**
* @param string $message The exception message
* @param int $code The exception code
* @param Exception|null $previous The previous exception
*/
public function __construct($message = "Unauthorized access", $code = 0, ?Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace KTXF\Resource\Exceptions;
use Exception;
/**
* Exemption for unauthorized access
*/
class UnsupportedException extends Exception {
/**
* @param string $message The exception message
* @param int $code The exception code
* @param Exception|null $previous The previous exception
*/
public function __construct($message = "Function is not supported", $code = 0, ?Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
}

View File

@@ -0,0 +1,130 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Filter;
class Filter implements IFilter {
protected array $attributes = [];
protected array $conditions = [];
/**
* Constructor
*
* @since 2025.05.01
*
* @param array<string,string> $attributes List of attributes that can be used in the filter
*/
public function __construct(array $attributes) {
foreach ($attributes as $id => $value) {
// separate the value into components
[$type, $length, $comparatorDefault, $comparatorSupported] = explode(':', $value);
// validate the components
$this->attributes[$id]['type'] = match ($type) {
's' => 'string',
'i' => 'integer',
'b' => 'boolean',
'a' => 'array',
'd' => 'date',
default => throw new \InvalidArgumentException("Invalid type '$type' for attribute '$id'."),
};
$this->attributes[$id]['length'] = (int)$length;
$this->attributes[$id]['comparatorDefault'] = FilterComparisonOperator::from((int)$comparatorDefault);
// comparatorSupported is a bitmask of supported comparators
if ($comparatorSupported !== '0') {
$comparators = FilterComparisonOperator::cases();
foreach ($comparators as $comparator) {
if (($comparatorSupported & $comparator->value) === $comparator->value) {
$this->attributes[$id]['comparatorSupported'][] = $comparator;
}
}
} else {
$this->attributes[$id]['comparatorSupported'] = [];
}
}
}
/**
* List of attributes that can be used in the filter
*
* @since 2025.05.01
*
* @return array<string>
*/
public function attributes(): array {
return $this->attributes;
}
/**
* List of comparison operators that can be used in the filter
*
* @since 2025.05.01
*/
public function comparators(): string {
return FilterComparisonOperator::class;
}
/**
* List of conjunction operators that can be used in the filter
*
* @since 2025.05.01
*/
public function conjunctions(): string {
return FilterConjunctionOperator::class;
}
/**
* Define a condition for the filter
*
* @since 2025.05.01
*/
public function condition(string $attribute, mixed $value, ?FilterComparisonOperator $comparator = null, ?FilterConjunctionOperator $conjunction = null): void {
// check if the attribute is defined in the filter
if (!isset($this->attributes[$attribute])) {
throw new \InvalidArgumentException("Attribute '$attribute' is not defined in the filter");
}
// check if comparator is valid and supported for the attribute
if ($comparator === null) {
$comparator = $this->attributes[$attribute]['comparatorDefault'];
}
if (!in_array($comparator, $this->attributes[$attribute]['comparatorSupported'], true)) {
throw new \InvalidArgumentException("Comparator '$comparator' is not supported for attribute '$attribute'");
}
// check if the value type is valid for the attribute
if ($this->attributes[$attribute]['type'] !== gettype($value)) {
throw new \InvalidArgumentException("Value for attribute '$attribute' must be of type '" . $this->attributes[$attribute]['type'] . "'");
}
// check if the value length is within the defined limit
if ($this->attributes[$attribute]['type'] === 'array' && $this->attributes[$attribute]['length'] <= count($value)) {
throw new \InvalidArgumentException("Value for attribute '$attribute' exceeds the maximum length of " . $this->attributes[$attribute]['length'] . " items");
}
if ($this->attributes[$attribute]['type'] === 'string' && $this->attributes[$attribute]['length'] <= mb_strlen($value)) {
throw new \InvalidArgumentException("Value for attribute '$attribute' exceeds the maximum length of " . $this->attributes[$attribute]['length'] . " characters");
}
$this->conditions[$attribute] = [
'attribute' => $attribute,
'value' => $value,
'comparator' => $comparator,
'conjunction' => $conjunction,
];
}
/**
* List of defined conditions
*
* @since 2025.05.01
*
* @return array<string, array{attribute:string, value:mixed, comparator:FilterComparisonOperator, conjunction:FilterConjunctionOperator}>
*/
public function conditions(): array {
return $this->conditions;
}
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Filter;
enum FilterComparisonOperator: int {
case EQ = 1;
case NEQ = 2;
case GT = 4;
case LT = 8;
case GTE = 16;
case LTE = 32;
case IN = 64;
case NIN = 128;
case LIKE = 256;
case NLIKE = 512;
}

View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Filter;
enum FilterConjunctionOperator: string {
case NONE = '';
case AND = 'AND';
case OR = 'OR';
}

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Filter;
interface IFilter {
/**
* List of attributes that can be used in the filter
*
* @since 2025.05.01
*
* @return array<string>
*/
public function attributes(): array;
/**
* List of comparison operators that can be used in the filter
*
* @since 2025.05.01
*/
public function comparators(): string;
/**
* List of conjunction operators that can be used in the filter
*
* @since 2025.05.01
*/
public function conjunctions(): string;
/**
* Define a filter condition
*
* @since 2025.05.01
*/
public function condition(string $property, mixed $value, ?FilterComparisonOperator $comparator = null, ?FilterConjunctionOperator $conjunction = null): void;
/**
* list of defined conditions
*
* @since 2025.05.01
*
* @return array<int, array{attribute:string, value:mixed, comparator:FilterComparisonOperator, conjunction:FilterConjunctionOperator}>
*/
public function conditions(): array;
}

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 {
}

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace KTXF\Resource\Provider;
/**
* Resource Provider Interface
*/
interface ProviderInterface
{
public const TYPE_AUTHENTICATION = 'authentication';
public const TYPE_PEOPLE = 'people';
public const TYPE_CHRONO = 'chrono';
public const TYPE_FILES = 'files';
public const TYPE_MAIL = 'mail';
/**
* Provider type (e.g., 'authentication', 'storage', 'notification')
*/
public function type(): string;
/**
* Unique identifier for this provider instance (e.g., UUID or 'password-auth')
*/
public function identifier(): string;
/**
* Human-friendly name (e.g., 'Password Authentication Provider', 'S3 Storage Provider')
*/
public function label(): string;
/**
* human-friendly description of this provider's functionality
*/
public function description(): string;
/**
* Icon representing this provider (e.g., FontAwesome class)
*/
public function icon(): string;
}

View File

@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace KTXF\Resource\Provider;
use KTXF\Json\JsonSerializable;
/**
* Resource Provider Interface
*/
interface ResourceProviderBaseInterface extends ProviderInterface, JsonSerializable
{
public const CAPABILITY_SERVICE_LIST = 'ServiceList';
public const CAPABILITY_SERVICE_FETCH = 'ServiceFetch';
public const CAPABILITY_SERVICE_EXTANT = 'ServiceExtant';
public const CAPABILITY_SERVICE_CREATE = 'ServiceCreate';
public const CAPABILITY_SERVICE_MODIFY = 'ServiceModify';
public const CAPABILITY_SERVICE_DESTROY = 'ServiceDestroy';
public const CAPABILITY_SERVICE_DISCOVER = 'ServiceDiscover';
public const CAPABILITY_SERVICE_TEST = 'ServiceTest';
public const JSON_TYPE = 'resource.provider';
public const JSON_PROPERTY_TYPE = '@type';
public const JSON_PROPERTY_IDENTIFIER = 'identifier';
public const JSON_PROPERTY_LABEL = 'label';
public const JSON_PROPERTY_CAPABILITIES = 'capabilities';
/**
* Confirms if specific capability is supported (e.g. 'ServiceList')
*
* @since 2025.11.01
*/
public function capable(string $value): bool;
/**
* Lists all supported capabilities
*
* @since 2025.11.01
*
* @return array<string,bool>
*/
public function capabilities(): array;
/**
* Retrieve collection of services for a specific user
*
* @since 2025.11.01
*
* @param string $tenantId tenant identifier
* @param string $userId user identifier
* @param array $filter filter criteria
*
* @return array<string,ResourceServiceBaseInterface> collection of service objects
*/
public function serviceList(string $tenantId, string $userId, array $filter): array;
/**
* Determine if any services are configured for a specific user
*
* @since 2025.11.01
*
* @param string $tenantId tenant identifier
* @param string $userId user identifier
* @param int|string ...$identifiers variadic collection of service identifiers
*
* @return array<string,bool> collection of service identifiers with boolean values indicating if the service is available
*/
public function serviceExtant(string $tenantId, string $userId, int|string ...$identifiers): array;
/**
* Retrieve a service with a specific identifier
*
* @since 2025.11.01
*
* @param string $tenantId tenant identifier
* @param string $userId user identifier
* @param string|int $identifier service identifier
*
* @return ResourceServiceBaseInterface|null returns service object or null if non found
*/
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?ResourceServiceBaseInterface;
}

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
use KTXF\Json\JsonDeserializable;
interface ResourceProviderServiceMutateInterface extends ResourceProviderBaseInterface, JsonDeserializable {
/**
* construct and new blank service instance
*
* @since 2025.05.01
*/
public function serviceFresh(): ResourceServiceMutateInterface;
/**
* create a service configuration for a specific user
*
* @since 2025.05.01
*/
public function serviceCreate(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string;
/**
* modify a service configuration for a specific user
*
* @since 2025.05.01
*/
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string;
/**
* delete a service configuration for a specific user
*
* @since 2025.05.01
*/
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool;
}

View File

@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace KTXF\Resource\Provider;
use KTXF\Json\JsonSerializable;
interface ResourceServiceBaseInterface extends JsonSerializable {
// JSON Constants
public const JSON_TYPE = 'resource.service';
public const JSON_PROPERTY_TYPE = '@type';
public const JSON_PROPERTY_PROVIDER = 'provider';
public const JSON_PROPERTY_IDENTIFIER = 'identifier';
public const JSON_PROPERTY_LABEL = 'label';
public const JSON_PROPERTY_ENABLED = 'enabled';
public const JSON_PROPERTY_CAPABILITIES = 'capabilities';
public const JSON_PROPERTY_LOCATION = 'location';
public const JSON_PROPERTY_IDENTITY = 'identity';
public const JSON_PROPERTY_AUXILIARY = 'auxiliary';
/**
* Confirms if specific capability is supported
*
* @since 2025.11.01
*
* @param string $value required ability e.g. 'EntityList'
*
* @return bool
*/
public function capable(string $value): bool;
/**
* Lists all supported capabilities
*
* @since 2025.11.01
*
* @return array<string,bool>
*/
public function capabilities(): array;
/**
* Unique identifier of the provider this service belongs to
*
* @since 2025.11.01
*/
public function provider(): string;
/**
* Unique arbitrary text string identifying this service (e.g. 1 or service1 or anything else)
*
* @since 2025.11.01
*/
public function identifier(): string|int;
/**
* Gets the localized human friendly name of this service (e.g. ACME Company File Service)
*
* @since 2025.11.01
*/
public function getLabel(): string|null;
/**
* Gets the active status of this service
*
* @since 2025.11.01
*/
public function getEnabled(): bool;
/**
* Gets the location information of this service
*
* @since 2025.05.01
*
* @return ResourceServiceLocationInterface
*/
public function getLocation(): ResourceServiceLocationInterface;
/**
* Gets the identity information of this service
*
* @since 2025.05.01
*
* @return ResourceServiceIdentityInterface
*/
public function getIdentity(): ResourceServiceIdentityInterface;
/**
* Gets the auxiliary information of this service
*
* @since 2025.05.01
*
* @return array
*/
public function getAuxiliary(): array;
}

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Configurable Interface
*
* Extends base service interface with setter methods for mutable properties.
* Used for service configuration and updates.
*
* @since 2025.05.01
*/
interface ResourceServiceConfigureInterface extends ResourceServiceMutateInterface {
/**
* Sets the location/configuration of this service
*
* @since 2025.05.01
*
* @param ResourceServiceLocationInterface $value Service location/configuration
*
* @return self
*/
public function setLocation(ResourceServiceLocationInterface $value): self;
/**
* Gets a fresh instance of the location/configuration of this service
*
* @since 2025.05.01
*
* @return ResourceServiceLocationInterface
*/
public function freshLocation(string|null $type, array $data = []): ResourceServiceLocationInterface;
/**
* Sets the identity used for this service
*
* @since 2025.05.01
*
* @param ResourceServiceIdentityInterface $value Service identity
*
* @return self
*/
public function setIdentity(ResourceServiceIdentityInterface $value): self;
/**
* Gets a fresh instance of the identity used for this service
*
* @since 2025.05.01
*
* @return ResourceServiceIdentityInterface
*/
public function freshIdentity(string|null $type, array $data = []): ResourceServiceIdentityInterface;
}

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Identity Basic
*
* Basic authentication (username/password) credentials for resource services.
*
* @since 2025.05.01
*/
interface ResourceServiceIdentityBasic extends ResourceServiceIdentityInterface {
/**
* Gets the identity/username
*
* @since 2025.05.01
*
* @return string
*/
public function getIdentity(): string;
/**
* Sets the identity/username
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setIdentity(string $value): void;
/**
* Gets the secret/password
*
* @since 2025.05.01
*
* @return string
*/
public function getSecret(): string;
/**
* Sets the secret/password
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setSecret(string $value): void;
}

View File

@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Identity Certificate
*
* Client certificate authentication credentials for resource services.
* Uses X.509 certificates for mutual TLS (mTLS) authentication.
*
* @since 2025.05.01
*/
interface ResourceServiceIdentityCertificate extends ResourceServiceIdentityInterface {
/**
* Gets the certificate file path or content
*
* @since 2025.05.01
*
* @return string Path to certificate file or PEM-encoded certificate
*/
public function getCertificate(): string;
/**
* Sets the certificate file path or content
*
* @since 2025.05.01
*
* @param string $value Path to certificate file or PEM-encoded certificate
*
* @return void
*/
public function setCertificate(string $value): void;
/**
* Gets the private key file path or content
*
* @since 2025.05.01
*
* @return string Path to private key file or PEM-encoded private key
*/
public function getPrivateKey(): string;
/**
* Sets the private key file path or content
*
* @since 2025.05.01
*
* @param string $value Path to private key file or PEM-encoded private key
*
* @return void
*/
public function setPrivateKey(string $value): void;
/**
* Gets the private key passphrase (if encrypted)
*
* @since 2025.05.01
*
* @return string|null Passphrase for encrypted private key, or null if not encrypted
*/
public function getPassphrase(): ?string;
/**
* Sets the private key passphrase (if encrypted)
*
* @since 2025.05.01
*
* @param string|null $value Passphrase for encrypted private key
*
* @return void
*/
public function setPassphrase(?string $value): void;
}

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
use KTXF\Json\JsonSerializable;
/**
* Resource Service Identity Interface
*
* Base interface for authentication credentials used by resource services.
*
* @since 2025.05.01
*/
interface ResourceServiceIdentityInterface extends JsonSerializable {
public const TYPE_NONE = 'NA';
public const TYPE_BASIC = 'BA';
public const TYPE_TOKEN = 'TA';
public const TYPE_OAUTH = 'OA';
public const TYPE_CERTIFICATE = 'CC';
/**
* Gets the identity/authentication type
*
* @since 2025.05.01
*
* @return string One of: TYPE_NONE, TYPE_BASIC, TYPE_TOKEN, TYPE_OAUTH, TYPE_CERTIFICATE
*/
public function type(): string;
}

View File

@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Identity OAuth
*
* OAuth authentication credentials for resource services, including token management.
*
* @since 2025.05.01
*/
interface ResourceServiceIdentityOAuth extends ResourceServiceIdentityInterface {
/**
* Gets the access token
*
* @since 2025.05.01
*
* @return string
*/
public function getAccessToken(): string;
/**
* Sets the access token
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setAccessToken(string $value): void;
/**
* Gets the access token scope
*
* @since 2025.05.01
*
* @return array
*/
public function getAccessScope(): array;
/**
* Sets the access token scope
*
* @since 2025.05.01
*
* @param array $value
*
* @return void
*/
public function setAccessScope(array $value): void;
/**
* Gets the access token expiry timestamp
*
* @since 2025.05.01
*
* @return int Unix timestamp
*/
public function getAccessExpiry(): int;
/**
* Sets the access token expiry timestamp
*
* @since 2025.05.01
*
* @param int $value Unix timestamp
*
* @return void
*/
public function setAccessExpiry(int $value): void;
/**
* Gets the refresh token
*
* @since 2025.05.01
*
* @return string
*/
public function getRefreshToken(): string;
/**
* Sets the refresh token
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setRefreshToken(string $value): void;
/**
* Gets the token refresh location/endpoint
*
* @since 2025.05.01
*
* @return string
*/
public function getRefreshLocation(): string;
/**
* Sets the token refresh location/endpoint
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setRefreshLocation(string $value): void;
}

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Identity Token
*
* Token authentication credentials for resource services.
* Uses a single static token/key for authentication.
*
* @since 2025.05.01
*/
interface ResourceServiceIdentityToken extends ResourceServiceIdentityInterface {
/**
* Gets the authentication token
*
* @since 2025.05.01
*
* @return string
*/
public function getToken(): string;
/**
* Sets the authentication token
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setToken(string $value): void;
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Location File
*
* File-based service location for services using local or network file paths
* (e.g., maildir, mbox, local storage).
*
* @since 2025.05.01
*/
interface ResourceServiceLocationFile extends ResourceServiceLocationInterface {
/**
* Gets the complete file location path
*
* @since 2025.05.01
*
* @return string File path (e.g., "/var/mail/user" or "\\server\share\mail")
*/
public function location(): string;
/**
* Gets the file location path
*
* @since 2025.05.01
*
* @return string File path
*/
public function getLocation(): string;
/**
* Sets the file location path
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setLocation(string $value): void;
}

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;
use JsonSerializable;
/**
* Resource Service Location Interface
*
* Unified interface supporting both URI-based (API services) and socket-based
* (traditional IMAP/SMTP) connection configurations.
*
* @since 2025.05.01
*/
interface ResourceServiceLocationInterface extends JsonSerializable {
public const TYPE_URI = 'URI';
public const TYPE_SOCKET_SOLE = 'SOCKET_SOLE';
public const TYPE_SOCKET_SPLIT = 'SOCKET_SPLIT';
public const TYPE_FILE = 'FILE';
/**
* Gets the service location type
*
* @since 2025.05.01
*
* @return string One of: TYPE_URI, TYPE_SOCKET_SOLE, TYPE_SOCKET_SPLIT, TYPE_FILE
*/
public function type(): string;
}

View File

@@ -0,0 +1,131 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Location Socket Sole
*
* Single socket-based service location for services using a single host/port combination
* (e.g., JMAP, unified mail servers).
*
* @since 2025.05.01
*/
interface ResourceServiceLocationSocketSole extends ResourceServiceLocationInterface {
/**
* Gets the complete location string
*
* @since 2025.05.01
*
* @return string Location (e.g., "mail.example.com:993")
*/
public function location(): string;
/**
* Gets the host
*
* @since 2025.05.01
*
* @return string Host (e.g., "mail.example.com")
*/
public function getHost(): string;
/**
* Sets the host
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setHost(string $value): void;
/**
* Gets the port
*
* @since 2025.05.01
*
* @return int Port number
*/
public function getPort(): int;
/**
* Sets the port
*
* @since 2025.05.01
*
* @param int $value
*
* @return void
*/
public function setPort(int $value): void;
/**
* Gets the encryption/security mode
*
* @since 2025.12.01
*
* @return string One of: 'none', 'ssl', 'tls', 'starttls'
*/
public function getEncryption(): string;
/**
* Sets the encryption/security mode
*
* @since 2025.12.01
*
* @param string $value One of: 'none', 'ssl', 'tls', 'starttls'
*
* @return void
*/
public function setEncryption(string $value): void;
/**
* Gets whether to verify SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @return bool
*/
public function getVerifyPeer(): bool;
/**
* Sets whether to verify SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setVerifyPeer(bool $value): void;
/**
* Gets whether to verify SSL/TLS certificate host
*
* @since 2025.12.01
*
* @return bool
*/
public function getVerifyHost(): bool;
/**
* Sets whether to verify SSL/TLS certificate host
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setVerifyHost(bool $value): void;
}

View File

@@ -0,0 +1,240 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Location Socket Split
*
* Split socket-based service location for services using separate inbound/outbound servers
* (e.g., traditional IMAP/SMTP configurations).
*
* @since 2025.05.01
*/
interface ResourceServiceLocationSocketSplit extends ResourceServiceLocationInterface {
/**
* Gets the complete inbound location string
*
* @since 2025.05.01
*
* @return string Inbound location (e.g., "imap.example.com:993")
*/
public function locationInbound(): string;
/**
* Gets the complete outbound location string
*
* @since 2025.05.01
*
* @return string Outbound location (e.g., "smtp.example.com:465")
*/
public function locationOutbound(): string;
/**
* Gets the inbound host
*
* @since 2025.05.01
*
* @return string Inbound host (e.g., "imap.example.com")
*/
public function getInboundHost(): string;
/**
* Sets the inbound host
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setInboundHost(string $value): void;
/**
* Gets the outbound host
*
* @since 2025.05.01
*
* @return string Outbound host (e.g., "smtp.example.com")
*/
public function getOutboundHost(): string;
/**
* Sets the outbound host
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setOutboundHost(string $value): void;
/**
* Gets the inbound port
*
* @since 2025.05.01
*
* @return int Inbound port number
*/
public function getInboundPort(): int;
/**
* Sets the inbound port
*
* @since 2025.05.01
*
* @param int $value
*
* @return void
*/
public function setInboundPort(int $value): void;
/**
* Gets the outbound port
*
* @since 2025.05.01
*
* @return int Outbound port number
*/
public function getOutboundPort(): int;
/**
* Sets the outbound port
*
* @since 2025.05.01
*
* @param int $value
*
* @return void
*/
public function setOutboundPort(int $value): void;
/**
* Gets the inbound encryption/security mode
*
* @since 2025.12.01
*
* @return string One of: 'none', 'ssl', 'tls', 'starttls'
*/
public function getInboundEncryption(): string;
/**
* Sets the inbound encryption/security mode
*
* @since 2025.12.01
*
* @param string $value One of: 'none', 'ssl', 'tls', 'starttls'
*
* @return void
*/
public function setInboundEncryption(string $value): void;
/**
* Gets the outbound encryption/security mode
*
* @since 2025.12.01
*
* @return string One of: 'none', 'ssl', 'tls', 'starttls'
*/
public function getOutboundEncryption(): string;
/**
* Sets the outbound encryption/security mode
*
* @since 2025.12.01
*
* @param string $value One of: 'none', 'ssl', 'tls', 'starttls'
*
* @return void
*/
public function setOutboundEncryption(string $value): void;
/**
* Gets whether to verify inbound SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @return bool
*/
public function getInboundVerifyPeer(): bool;
/**
* Sets whether to verify inbound SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setInboundVerifyPeer(bool $value): void;
/**
* Gets whether to verify inbound SSL/TLS certificate host
*
* @since 2025.12.01
*
* @return bool
*/
public function getInboundVerifyHost(): bool;
/**
* Sets whether to verify inbound SSL/TLS certificate host
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setInboundVerifyHost(bool $value): void;
/**
* Gets whether to verify outbound SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @return bool
*/
public function getOutboundVerifyPeer(): bool;
/**
* Sets whether to verify outbound SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setOutboundVerifyPeer(bool $value): void;
/**
* Gets whether to verify outbound SSL/TLS certificate host
*
* @since 2025.12.01
*
* @return bool
*/
public function getOutboundVerifyHost(): bool;
/**
* Sets whether to verify outbound SSL/TLS certificate host
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setOutboundVerifyHost(bool $value): void;
}

View File

@@ -0,0 +1,150 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider;
/**
* Resource Service Location Uri
*
* URI-based service location for API and web services (e.g., https://api.example.com:443/v1/endpoint).
*
* @since 2025.05.01
*/
interface ResourceServiceLocationUri extends ResourceServiceLocationInterface {
/**
* Gets the complete location URI
*
* @since 2025.05.01
*
* @return string Complete URI (e.g., "https://api.example.com:443/v1")
*/
public function location(): string;
/**
* Gets the URI scheme
*
* @since 2025.05.01
*
* @return string Scheme (e.g., "https", "http")
*/
public function getScheme(): string;
/**
* Sets the URI scheme
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setScheme(string $value): void;
/**
* Gets the host
*
* @since 2025.05.01
*
* @return string Host (e.g., "api.example.com")
*/
public function getHost(): string;
/**
* Sets the host
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setHost(string $value): void;
/**
* Gets the port
*
* @since 2025.05.01
*
* @return int Port number
*/
public function getPort(): int;
/**
* Sets the port
*
* @since 2025.05.01
*
* @param int $value
*
* @return void
*/
public function setPort(int $value): void;
/**
* Gets the path
*
* @since 2025.05.01
*
* @return string Path (e.g., "/v1/api")
*/
public function getPath(): string;
/**
* Sets the path
*
* @since 2025.05.01
*
* @param string $value
*
* @return void
*/
public function setPath(string $value): void;
/**
* Gets whether to verify SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @return bool
*/
public function getVerifyPeer(): bool;
/**
* Sets whether to verify SSL/TLS peer certificate
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setVerifyPeer(bool $value): void;
/**
* Gets whether to verify SSL/TLS certificate host
*
* @since 2025.12.01
*
* @return bool
*/
public function getVerifyHost(): bool;
/**
* Sets whether to verify SSL/TLS certificate host
*
* @since 2025.12.01
*
* @param bool $value
*
* @return void
*/
public function setVerifyHost(bool $value): void;
}

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;
use KTXF\Json\JsonDeserializable;
/**
* Resource Service Configurable Interface
*
* Extends base service interface with setter methods for mutable properties.
* Used for service configuration and updates.
*
* @since 2025.05.01
*/
interface ResourceServiceMutateInterface extends ResourceServiceBaseInterface, JsonDeserializable {
/**
* Sets the localized human-friendly name of this service (e.g. ACME Company Mail Service)
*
* @since 2025.05.01
*
* @param string $value Service label
*
* @return self
*/
public function setLabel(string $value): self;
/**
* Sets the active status of this service
*
* @since 2025.05.01
*
* @param bool $value True to enable, false to disable
*
* @return self
*/
public function setEnabled(bool $value): self;
/**
* Sets the auxiliary information of this service
*
* @since 2025.05.01
*
* @param array $value Arbitrary key-value pairs for additional service info
*
* @return self
*/
public function setAuxiliary(array $value): self;
}

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\Range;
interface IRange {
/**
* Gets the type of this range
*
* @since 1.0.0
*/
public function type(): RangeType;
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
use DateTimeInterface;
interface IRangeDate extends IRange {
/**
*
* @since 1.0.0
*/
public function getStart(): DateTimeInterface;
/**
*
* @since 1.0.0
*/
public function setStart(DateTimeInterface $value): void;
/**
*
* @since 1.0.0
*/
public function getEnd(): DateTimeInterface;
/**
*
* @since 1.0.0
*/
public function setEnd(DateTimeInterface $value): void;
}

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
interface IRangeTally extends IRange {
/**
* Gets the anchor type of the range
*
* @since 1.0.0
*/
public function getAnchor(): RangeAnchorType;
/**
* Sets the anchor type of the range
*
* @since 1.0.0
*/
public function setAnchor(RangeAnchorType $value): void;
/**
* Gets the start position of the range
*
* @since 1.0.0
*/
public function getPosition(): string|int;
/**
* Sets the start position of the range
*
* @since 1.0.0
*/
public function setPosition(string|int $value): void;
/**
* Gets the count of items in the range
*
* @since 1.0.0
*/
public function getTally(): int;
/**
* Sets the count of items in the range
*
* @since 1.0.0
*/
public function setTally(int $value): void;
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
class Range implements IRange {
/**
* Returns the type of the range
*
* @since 1.0.0
*/
public function type(): RangeType {
return RangeType::NONE;
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
enum RangeAnchorType: string {
case RELATIVE = 'relative'; // A relative anchor is used to indicate a starting position based on a record identifier
case ABSOLUTE = 'absolute'; // A absolute anchor is used to indicate a starting position based on record count
}

View File

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
use DateTime;
use DateTimeInterface;
class RangeDate extends Range implements IRangeDate {
protected DateTimeInterface $start;
protected DateTimeInterface $end;
/**
* Returns the type of the range
*
* @since 1.0.0
*/
public function type(): RangeType {
return RangeType::DATE;
}
/**
* Gets the start date of the range
*
* @since 1.0.0
*/
public function getStart(): DateTimeInterface {
return $this->start;
}
/**
* Sets the start date of the range
*
* @since 1.0.0
*/
public function setStart(DateTimeInterface $value): void {
$this->start = $value;
}
/**
* Gets the end date of the range
*
* @since 1.0.0
*/
public function getEnd(): DateTimeInterface {
return $this->end;
}
/**
* Sets the end date of the range
*
* @since 1.0.0
*/
public function setEnd(DateTimeInterface $value): void {
$this->end = $value;
}
}

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
class RangeTally extends Range implements IRangeTally {
protected RangeAnchorType $anchor = RangeAnchorType::ABSOLUTE;
protected string|int $position = 0;
protected int $tally = 32;
/**
* Returns the type of the range
*
* @since 1.0.0
*/
public function type(): RangeType {
return RangeType::TALLY;
}
/**
* Gets the anchor type of the range
*
* @since 1.0.0
*/
public function getAnchor(): RangeAnchorType {
return $this->anchor;
}
/**
* Sets the anchor type of the range
*
* @since 1.0.0
*/
public function setAnchor(RangeAnchorType $value): void {
$this->anchor = $value;
}
/**
* Gets the start position of the range
*
* @since 1.0.0
*/
public function getPosition(): string|int {
return $this->position;
}
/**
* Sets the start position of the range
*
* @since 1.0.0
*/
public function setPosition(string|int $value): void {
$this->position = $value;
}
/**
* Gets the count of items in the range
*
* @since 1.0.0
*/
public function getTally(): int {
return $this->tally;
}
/**
* Sets the count of items in the range
*
* @since 1.0.0
*/
public function setTally(int $value): void {
$this->tally = $value;
}
}

View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Range;
enum RangeType: string {
case NONE = 'none';
case DATE = 'date';
case TALLY = 'tally';
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Selector;
/**
* Collection-level selector
*/
class CollectionSelector extends SelectorAbstract {
protected array $keyTypes = ['string', 'integer'];
protected array $valueTypes = ['boolean', EntitySelector::class, 'string'];
protected string $nestedSelector = EntitySelector::class;
protected string $selectorName = 'CollectionSelector';
}

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Selector;
/**
* Entity-level selector (leaf node)
*/
class EntitySelector extends SelectorAbstract {
protected array $keyTypes = ['string', 'integer'];
protected array $valueTypes = ['boolean', 'array', 'string', 'integer'];
protected string $selectorName = 'EntitySelector';
public function append($value): void {
if (!is_string($value) && !is_int($value)) {
throw new \InvalidArgumentException('EntitySelector values must be string or int');
}
parent::append($value);
}
public function offsetSet($key, $value): void {
if ($key !== null && !is_int($key)) {
throw new \InvalidArgumentException('EntitySelector does not support associative keys');
}
if (!is_string($value) && !is_int($value)) {
throw new \InvalidArgumentException('EntitySelector values must be string or int');
}
parent::offsetSet($key, $value);
}
/**
* Get all entity identifiers
* @return array<string|int>
*/
public function identifiers(): array {
return $this->getArrayCopy();
}
}

View File

@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Selector;
use JsonSerializable;
use KTXF\Json\JsonDeserializable;
/**
* Abstract base class for all selector types
* Provides common functionality for hierarchical selectors
*/
abstract class SelectorAbstract extends \ArrayObject implements JsonSerializable, JsonDeserializable {
protected const TYPE_STRING = 'string';
protected const TYPE_INT = 'int';
protected const TYPE_BOOL = 'bool';
/** @var array<mixed> Allowed key types: 'string', 'int' */
protected array $keyTypes = [];
/** @var array<mixed> Allowed scalar value types: 'string', 'int', 'bool' */
protected array $valueTypes = [];
/** @var class-string selector class for nested structures */
protected string $nestedSelector = SelectorAbstract::class;
/** @var string Human-readable name for this selector type */
protected string $selectorName = 'Selector';
/**
* Serialize to JSON-compatible array
*
* @return array
*/
public function jsonSerialize(): array {
$result = [];
foreach ($this as $key => $value) {
if ($value instanceof JsonSerializable) {
$result[$key] = $value->jsonSerialize();
} else {
$result[$key] = $value;
}
}
return $result;
}
/**
* Deserialize from JSON-compatible array
* @param array $data
* @return void
* @throws \InvalidArgumentException
*/
public function jsonDeserialize(array|string $data): static {
if (is_string($data)) {
$data = json_decode($data, true);
}
foreach ($data as $key => $value) {
if ($this->nestedSelector !== null && is_array($value)) {
$selector = new $this->nestedSelector();
$selector->jsonDeserialize($value);
$this->offsetSet($key, $selector);
} else {
$this->offsetSet($key, $value);
}
}
return $this;
}
/**
* Validate if a key is of the correct type for this selector
*
* @param mixed $key
* @return bool
*/
protected function validateKey(mixed $key): bool {
return in_array(gettype($key), $this->keyTypes, true);
}
/**
* Validate if a value is of the correct type for this selector
*
* @param mixed $value
* @return bool
*/
protected function validateValue(mixed $value): bool {
if ($this->nestedSelector !== null && $value instanceof $this->nestedSelector) {
return true;
}
return in_array(gettype($value), $this->valueTypes, true);
}
/**
* Override offsetSet to enforce type checking
*
* @param mixed $key
* @param mixed $value
* @return void
* @throws \InvalidArgumentException
*/
#[\Override]
public function offsetSet($key, $value): void {
if (!$this->validateKey($key)) {
throw new \InvalidArgumentException("{$this->selectorName} keys must be one of [" . implode(', ', $this->keyTypes) . "], got " . gettype($key));
}
if (!$this->validateValue($value)) {
throw new \InvalidArgumentException("{$this->selectorName} values must be one of [" . implode(', ', $this->valueTypes) . "], got " . gettype($value));
}
parent::offsetSet($key, $value);
}
/**
* Get all identifiers (keys or values depending on selector type)
*
* @return array
*/
public function identifiers(): array {
return array_keys($this->getArrayCopy());
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Selector;
/**
* Service-level selector
*/
class ServiceSelector extends SelectorAbstract {
protected array $keyTypes = ['string', 'int'];
protected array $valueTypes = ['boolean', CollectionSelector::class];
protected string $nestedSelector = CollectionSelector::class;
protected string $selectorName = 'CollectionSelector';
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Selector;
/**
* Top-level selector for sources
*/
class SourceSelector extends SelectorAbstract {
protected array $keyTypes = ['string'];
protected array $valueTypes = ['boolean', ServiceSelector::class];
protected string $nestedSelector = ServiceSelector::class;
protected string $selectorName = 'ProviderSelector';
}

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Sort;
interface ISort {
/**
* List of available attributes
*
* @since 1.0.0
*
* @return array<string,bool>
*/
public function attributes(): array;
/**
* Define sort condition
*
* @since 1.0.0
*
* @param string $attribute attribute name
* @param bool $direction true for ascending, false for descending
*/
public function condition(string $property, bool $direction): void;
/**
* List of sort conditions
*
* @since 1.0.0
*
* @return array<string,array{attribute:string,direction:bool}>
*/
public function conditions(): array;
}

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\Sort;
class Sort implements ISort {
protected array $attributes = [];
protected array $conditions = [];
public function __construct(array $attributes) {
$this->attributes = $attributes;
}
/**
*
* @since 1.0.0
*
* @return array<string,bool>
*/
public function attributes(): array {
return $this->attributes;
}
/**
*
* @since 1.0.0
*
* @param string $attribute attribute name
* @param bool $direction true for ascending, false for descending
*/
public function condition(string $attribute, bool $direction): void {
if (isset($this->attributes[$attribute])) {
$this->conditions[$attribute] = [
'attribute' => $attribute,
'direction' => $direction,
];
}
}
/**
*
* @since 1.0.0
*
* @return array<string,array{attribute:string, direction:bool}>
*/
public function conditions(): array {
return $this->conditions;
}
}