* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXM\ProviderLocalDocuments\Providers\Personal; use KTXF\Resource\Documents\Entity\EntityMutableAbstract; class EntityResource extends EntityMutableAbstract { public function __construct( string $provider = 'default', string|int $service = 'personal', ) { parent::__construct($provider, $service); } public function fromStore(array|object $data): self { if (is_object($data)) { $data = (array) $data; } $this->data[static::JSON_PROPERTY_COLLECTION] = $data['cid'] ?? null; $this->data[static::JSON_PROPERTY_IDENTIFIER] = $data['nid']; $this->data[static::JSON_PROPERTY_CREATED] = $data['created'] ?? null; $this->data[static::JSON_PROPERTY_MODIFIED] = $data['modified'] ?? null; $this->data[static::JSON_PROPERTY_SIGNATURE] = $data['signature'] ?? null; $this->getProperties()->fromStore($data['properties'] ?? []); return $this; } public function toStore(): array { $properties = $this->getProperties(); $data = array_filter([ 'cid' => $this->data[static::JSON_PROPERTY_COLLECTION] ?? null, 'nid' => $this->data[static::JSON_PROPERTY_IDENTIFIER] ?? null, 'created' => $this->data[static::JSON_PROPERTY_CREATED] ?? null, 'modified' => $this->data[static::JSON_PROPERTY_MODIFIED] ?? null, 'signature' => $this->data[static::JSON_PROPERTY_SIGNATURE] ?? null, 'properties' => $properties ? $properties->toStore() : null, ], static fn($value) => $value !== null); return $data; } public function getProperties(): EntityProperties { if (!isset($this->properties)) { $this->properties = new EntityProperties([]); } return $this->properties; } }