* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXM\ProviderLocalDocuments\Providers\Personal; use KTXF\Resource\Documents\Entity\EntityPropertiesMutableAbstract; class EntityProperties extends EntityPropertiesMutableAbstract { /** * Converts store document values into entity properties. */ public function fromStore(array|object $data): static { if (is_object($data)) { $data = (array) $data; } if (isset($data['size'])) { $this->data[self::JSON_PROPERTY_SIZE] = (int) $data['size']; } if (isset($data['label'])) { $this->data[self::JSON_PROPERTY_LABEL] = (string) $data['label']; } if (isset($data['mime'])) { $this->data[self::JSON_PROPERTY_MIME] = (string) $data['mime']; } if (isset($data['format'])) { $this->data[self::JSON_PROPERTY_FORMAT] = (string) $data['format']; } if (isset($data['encoding'])) { $this->data[self::JSON_PROPERTY_ENCODING] = (string) $data['encoding']; } return $this; } /** * Converts entity properties into store document values. */ public function toStore(): array { return array_filter([ 'label' => $this->data[self::JSON_PROPERTY_LABEL], 'mime' => $this->data[self::JSON_PROPERTY_MIME] ?? 'application/octet-stream', 'format' => $this->data[self::JSON_PROPERTY_FORMAT] ?? null, 'encoding' => $this->data[self::JSON_PROPERTY_ENCODING] ?? null, ], static fn($value) => $value !== null); } }