refactor: improvemets
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
62
lib/Providers/Document/EntityProperties.php
Normal file
62
lib/Providers/Document/EntityProperties.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
||||
|
||||
use KTXF\Resource\Documents\Entity\EntityPropertiesMutableAbstract;
|
||||
|
||||
/**
|
||||
* Document Collection Properties Implementation
|
||||
*/
|
||||
class EntityProperties extends EntityPropertiesMutableAbstract {
|
||||
|
||||
/**
|
||||
* Convert JMAP parameters array to document entity properties object
|
||||
*
|
||||
* @param array $parameters JMAP parameters array
|
||||
*/
|
||||
public function fromJmap(array $parameters): static {
|
||||
|
||||
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['name'];
|
||||
}
|
||||
|
||||
if (isset($data['mime'])) {
|
||||
$this->data[self::JSON_PROPERTY_MIME] = (string) $data['type'];
|
||||
}
|
||||
|
||||
if (isset($data['format'])) {
|
||||
$this->data[self::JSON_PROPERTY_FORMAT] = null;
|
||||
}
|
||||
|
||||
if (isset($data['encoding'])) {
|
||||
$this->data[self::JSON_PROPERTY_ENCODING] = null;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert document entity properties object to JMAP parameters array
|
||||
*/
|
||||
public function toJmap(): array {
|
||||
|
||||
$parameters = array_filter([
|
||||
'name' => $this->data[self::JSON_PROPERTY_LABEL],
|
||||
'type' => $this->data[self::JSON_PROPERTY_MIME] ?? 'application/octet-stream'
|
||||
], static fn($value) => $value !== null);
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user