117 lines
2.8 KiB
PHP
117 lines
2.8 KiB
PHP
<?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;
|
|
}
|