refactor: chrono entity classes

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-17 15:43:23 -04:00
parent 7e81e130c9
commit 28bc360106
14 changed files with 99 additions and 61 deletions
@@ -23,7 +23,7 @@ use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
abstract class EntityMutableAbstract extends NodeMutableAbstract implements EntityMutableInterface {
protected string $type = 'chrono:entity';
protected EntityPropertiesMutableInterface $properties;
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]);
@@ -32,16 +32,36 @@ abstract class EntityMutableAbstract extends NodeMutableAbstract implements Enti
/**
* @inheritDoc
*/
public function getProperties(): EntityPropertiesMutableInterface {
return $this->properties;
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 EntityPropertiesMutableInterface) {
throw new \InvalidArgumentException('Properties must implement EntityPropertiesMutableInterface');
if (!$value instanceof EventObject && !$value instanceof TaskObject && !$value instanceof JournalObject) {
throw new \InvalidArgumentException('Properties must be an EventObject, TaskObject or JournalObject');
}
$this->properties = $value;