refactor: mail interfaces
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user