refactor: use unified service provider desing

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-25 23:41:26 -04:00
parent d13c3f4ac6
commit 4b4e7a3ae0
5 changed files with 282 additions and 168 deletions
+21 -10
View File
@@ -12,31 +12,42 @@ namespace KTXM\ProviderLocalChrono\Providers\Personal;
use KTXF\Chrono\Collection\CollectionContent;
use KTXF\Chrono\Collection\CollectionPropertiesMutableAbstract;
/**
* Collection Properties Implementation
*/
class CollectionProperties extends CollectionPropertiesMutableAbstract {
/**
* Converts store document values into collection properties.
*/
public function fromStore(array $data): static {
$this->data[self::JSON_PROPERTY_CONTENTS] = CollectionContent::Event->value;
$this->data[self::PROPERTY_CONTENT] = [
CollectionContent::Event->value,
CollectionContent::Task->value,
CollectionContent::Journal->value
];
if (isset($data['label'])) {
$this->data[self::JSON_PROPERTY_LABEL] = (string) $data['label'];
$this->data[self::PROPERTY_LABEL] = (string) $data['label'];
}
if (array_key_exists('description', $data)) {
$this->data[self::JSON_PROPERTY_DESCRIPTION] = $data['description'];
$this->data[self::PROPERTY_DESCRIPTION] = $data['description'];
}
if (array_key_exists('priority', $data)) {
$this->data[self::JSON_PROPERTY_PRIORITY] = $data['priority'] !== null ? (int) $data['priority'] : null;
if (array_key_exists('rank', $data)) {
$this->data[self::PROPERTY_RANK] = $data['rank'] !== null ? (int) $data['rank'] : null;
}
if (array_key_exists('visibility', $data)) {
$this->data[self::JSON_PROPERTY_VISIBILITY] = $data['visibility'] !== null ? (bool) $data['visibility'] : null;
$this->data[self::PROPERTY_VISIBILITY] = $data['visibility'] !== null ? (bool) $data['visibility'] : null;
}
if (array_key_exists('color', $data)) {
$this->data[self::JSON_PROPERTY_COLOR] = $data['color'];
$this->data[self::PROPERTY_COLOR] = $data['color'];
}
if (isset($data['content'])) {
$this->data[self::JSON_PROPERTY_CONTENTS] = (string) $data['content'];
$content = is_array($data['content']) ? $data['content'] : [$data['content']];
$this->data[self::PROPERTY_CONTENT] = array_values(array_map(
static fn($item) => $item instanceof CollectionContent ? $item->value : (string) $item,
$content
));
}
return $this;
@@ -51,10 +62,10 @@ class CollectionProperties extends CollectionPropertiesMutableAbstract {
return array_filter([
'label' => $this->getLabel(),
'description' => $this->getDescription(),
'priority' => $this->getPriority(),
'rank' => $this->getRank(),
'visibility' => $this->getVisibility(),
'color' => $this->getColor(),
'content' => $content instanceof CollectionContent ? $content->value : null,
'content' => $content !== [] ? array_map(static fn(CollectionContent $item) => $item->value, $content) : null,
], static fn($value) => $value !== null);
}
}