refactor: use new interface design
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -10,6 +10,10 @@ declare(strict_types=1);
|
||||
namespace KTXM\ProviderLocalChrono\Providers\Personal;
|
||||
|
||||
use KTXF\Chrono\Entity\EntityMutableAbstract;
|
||||
use KTXF\Chrono\Entity\EntityType;
|
||||
use KTXF\Chrono\Entity\EventObject;
|
||||
use KTXF\Chrono\Entity\JournalObject;
|
||||
use KTXF\Chrono\Entity\TaskObject;
|
||||
use KTXF\Utile\Timestamp;
|
||||
|
||||
class EntityResource extends EntityMutableAbstract {
|
||||
@@ -35,8 +39,12 @@ class EntityResource extends EntityMutableAbstract {
|
||||
$this->data[self::PROPERTY_COLLECTION] = $document['cid'] ?? null;
|
||||
$this->data[self::PROPERTY_CREATED] = $document['createdOn'] ?? null;
|
||||
$this->data[self::PROPERTY_MODIFIED] = $document['modifiedOn'] ?? null;
|
||||
$this->getProperties()->fromStore($document);
|
||||
$this->data[self::PROPERTY_SIGNATURE] = md5(json_encode($this->getProperties()->getDataRaw()));
|
||||
$data = $document['data'] ?? [];
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true) ?: [];
|
||||
}
|
||||
$this->properties = EntityType::fromData($data)->instantiate()->jsonDeserialize($data);
|
||||
$this->data[self::PROPERTY_SIGNATURE] = md5(json_encode($this->properties));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -51,17 +59,13 @@ class EntityResource extends EntityMutableAbstract {
|
||||
'modifiedOn' => Timestamp::normalize($this->data[self::PROPERTY_MODIFIED] ?? null),
|
||||
], static fn($value) => $value !== null);
|
||||
|
||||
$document = array_merge($document, $this->getProperties()->toStore());
|
||||
$document['data'] = json_decode(json_encode($this->getProperties()), true);
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
public function getProperties(): EntityProperties {
|
||||
if (!isset($this->properties)) {
|
||||
$this->properties = new EntityProperties([]);
|
||||
}
|
||||
|
||||
return $this->properties;
|
||||
public function getProperties(): EventObject|TaskObject|JournalObject {
|
||||
return $this->properties ??= new EventObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user