28bc360106
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXF\Chrono\Entity;
|
|
|
|
use KTXF\Resource\Identifier\EntityIdentifier;
|
|
use KTXF\Resource\Provider\Node\NodeMutableAbstract;
|
|
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
|
|
|
/**
|
|
* Abstract Chrono Entity Mutable Class
|
|
*
|
|
* Provides common implementation for mutable chrono entities
|
|
*
|
|
* @since 2025.05.01
|
|
*/
|
|
abstract class EntityMutableAbstract extends NodeMutableAbstract implements EntityMutableInterface {
|
|
|
|
protected string $type = 'chrono:entity';
|
|
protected EventObject|TaskObject|JournalObject $properties;
|
|
|
|
protected function nodeIdentifier(): EntityIdentifier {
|
|
return new EntityIdentifier($this->data[static::PROPERTY_PROVIDER], $this->data[static::PROPERTY_SERVICE], (string) $this->data[static::PROPERTY_COLLECTION], (string) $this->data[static::PROPERTY_IDENTIFIER]);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function jsonDeserialize(array|string $data): static {
|
|
if (is_string($data)) {
|
|
$data = json_decode($data, true);
|
|
}
|
|
|
|
$properties = $data[static::PROPERTY_PROPERTIES] ?? null;
|
|
unset($data[static::PROPERTY_PROPERTIES]);
|
|
|
|
parent::jsonDeserialize($data);
|
|
|
|
if (is_array($properties)) {
|
|
$this->properties = EntityType::fromData($properties)->instantiate()->jsonDeserialize($properties);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getProperties(): EventObject|TaskObject|JournalObject {
|
|
return $this->properties ??= new EventObject();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function setProperties(NodePropertiesMutableInterface $value): static {
|
|
if (!$value instanceof EventObject && !$value instanceof TaskObject && !$value instanceof JournalObject) {
|
|
throw new \InvalidArgumentException('Properties must be an EventObject, TaskObject or JournalObject');
|
|
}
|
|
|
|
$this->properties = $value;
|
|
|
|
return $this;
|
|
}
|
|
}
|