refactor: standardize design

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-03 22:10:46 -05:00
parent c0fa9cadfb
commit 36e25f967b
12 changed files with 750 additions and 1076 deletions

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderLocalDocuments\Providers\Personal;
use KTXF\Resource\Documents\Collection\CollectionPropertiesMutableAbstract;
class CollectionProperties extends CollectionPropertiesMutableAbstract {
/**
* Converts store document values into collection properties.
*/
public function fromStore(array|object $data): static {
if (is_object($data)) {
$data = (array) $data;
}
if (isset($data['label'])) {
$this->data[self::JSON_PROPERTY_LABEL] = (string) $data['label'];
}
return $this;
}
/**
* Converts collection properties into store document values.
*/
public function toStore(): array {
return array_filter([
'label' => $this->getLabel(),
], static fn($value) => $value !== null);
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderLocalDocuments\Providers\Personal;
use KTXF\Resource\Documents\Collection\CollectionMutableAbstract;
class CollectionResource extends CollectionMutableAbstract {
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(): CollectionProperties {
if (!isset($this->properties)) {
$this->properties = new CollectionProperties([]);
}
return $this->properties;
}
}

View File

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* 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);
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* 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;
}
}

View File

@@ -1,176 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\FileProviderLocal\Providers\Personal;
use DateTimeImmutable;
use KTXF\Files\Node\INodeCollectionBase;
use KTXF\Files\Node\INodeCollectionMutable;
use KTXF\Files\Node\NodeType;
/**
* NodeCollection implementation - represents a folder/collection in the file system
*/
class NodeCollection implements INodeCollectionBase, INodeCollectionMutable {
// node system properties
private string|null $tenantId = null;
private string|null $userId = null;
private string|int|null $nodeIn = null;
private string|int|null $nodeId = null;
private string|null $nodeCreatedBy = null;
private DateTimeImmutable|null $nodeCreatedOn = null;
private string|null $nodeModifiedBy = null;
private DateTimeImmutable|null $nodeModifiedOn = null;
private string|null $nodeOwner = null;
private string|null $nodeSignature = null;
// node specific properties
private string|null $nodeLabel = null;
public function jsonSerialize(): mixed {
return [
// node meta properties
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
self::JSON_PROPERTY_IN => $this->nodeIn,
self::JSON_PROPERTY_ID => $this->nodeId,
self::JSON_PROPERTY_CREATED_BY => $this->nodeCreatedBy,
self::JSON_PROPERTY_CREATED_ON => $this->nodeCreatedOn?->format('c'),
self::JSON_PROPERTY_MODIFIED_BY => $this->nodeModifiedBy,
self::JSON_PROPERTY_MODIFIED_ON => $this->nodeModifiedOn?->format('c'),
self::JSON_PROPERTY_OWNER => $this->nodeOwner,
self::JSON_PROPERTY_SIGNATURE => $this->nodeSignature,
// node specific properties
self::JSON_PROPERTY_LABEL => $this->nodeLabel,
];
}
public function jsonDeserialize(array|string $data): static {
if (is_string($data)) {
$data = json_decode($data, true);
}
// node meta properties
$this->nodeIn = $data[self::JSON_PROPERTY_IN] ?? null;
$this->nodeId = $data[self::JSON_PROPERTY_ID] ?? null;
$this->nodeCreatedBy = $data[self::JSON_PROPERTY_CREATED_BY] ?? null;
$this->nodeCreatedOn = isset($data[self::JSON_PROPERTY_CREATED_ON])
? new DateTimeImmutable($data[self::JSON_PROPERTY_CREATED_ON])
: null;
$this->nodeModifiedBy = $data[self::JSON_PROPERTY_MODIFIED_BY] ?? null;
$this->nodeModifiedOn = isset($data[self::JSON_PROPERTY_MODIFIED_ON])
? new DateTimeImmutable($data[self::JSON_PROPERTY_MODIFIED_ON])
: null;
$this->nodeOwner = $data[self::JSON_PROPERTY_OWNER] ?? null;
$this->nodeSignature = $data[self::JSON_PROPERTY_SIGNATURE] ?? null;
// node specific properties
$this->nodeLabel = $data[self::JSON_PROPERTY_LABEL] ?? null;
return $this;
}
public function fromStore(array|object $document): self {
if (is_object($document)) {
$document = (array) $document;
}
// node system properties
$this->tenantId = $document['tid'] ?? null;
$this->userId = $document['uid'] ?? null;
$this->nodeId = $document['nid'] ?? null;
$this->nodeIn = $document['pid'] ?? null;
$this->nodeCreatedBy = $document['createdBy'] ?? null;
$this->nodeCreatedOn = isset($document['createdOn'])
? new DateTimeImmutable($document['createdOn'])
: null;
$this->nodeModifiedBy = $document['modifiedBy'] ?? null;
$this->nodeModifiedOn = isset($document['modifiedOn'])
? new DateTimeImmutable($document['modifiedOn'])
: null;
$this->nodeOwner = $document['owner'] ?? null;
$this->nodeSignature = $document['signature'] ?? md5(json_encode([
$this->nodeId, NodeType::Collection->value, $document['modifiedOn'] ?? ''
]));
// node specific properties
$this->nodeLabel = $document['label'] ?? null;
return $this;
}
public function toStore(): array {
$now = date('c');
return [
// node system properties
'tid' => $this->tenantId,
'uid' => $this->userId,
'nid' => $this->nodeId,
'pid' => $this->nodeIn,
'type' => NodeType::Collection->value,
'createdBy' => $this->nodeCreatedBy,
'createdOn' => $this->nodeCreatedOn?->format('c') ?? $now,
'modifiedBy' => $this->nodeModifiedBy,
'modifiedOn' => $this->nodeModifiedOn?->format('c') ?? $now,
'owner' => $this->nodeOwner,
'signature' => $this->nodeSignature,
// node specific properties
'label' => $this->nodeLabel,
];
}
// Immutable properties
public function in(): string|int|null {
return $this->nodeIn;
}
public function id(): string|int {
return $this->nodeId ?? '';
}
public function type(): NodeType {
return NodeType::Collection;
}
public function createdBy(): string|null {
return $this->nodeCreatedBy;
}
public function createdOn(): DateTimeImmutable|null {
return $this->nodeCreatedOn;
}
public function modifiedBy(): string|null {
return $this->nodeModifiedBy;
}
public function modifiedOn(): DateTimeImmutable|null {
return $this->nodeModifiedOn;
}
public function signature(): string|null {
return $this->nodeSignature;
}
public function isCollection(): bool {
return true;
}
public function isEntity(): bool {
return false;
}
// Mutable properties
public function getLabel(): string|null {
return $this->nodeLabel;
}
public function setLabel(string $value): static {
$this->nodeLabel = $value;
return $this;
}
}

View File

@@ -1,226 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\FileProviderLocal\Providers\Personal;
use DateTimeImmutable;
use KTXF\Files\Node\INodeEntityBase;
use KTXF\Files\Node\INodeEntityMutable;
use KTXF\Files\Node\NodeType;
/**
* NodeEntity implementation - represents a file/entity in the file system
*/
class NodeEntity implements INodeEntityBase, INodeEntityMutable {
// node system properties
private string|null $tenantId = null;
private string|null $userId = null;
private string|int|null $nodeIn = null;
private string|int|null $nodeId = null;
private string|null $nodeCreatedBy = null;
private DateTimeImmutable|null $nodeCreatedOn = null;
private string|null $nodeModifiedBy = null;
private DateTimeImmutable|null $nodeModifiedOn = null;
private string|null $nodeOwner = null;
private string|null $nodeSignature = null;
// node specific properties
private string|null $nodeLabel = null;
private string|null $nodeMime = null;
private string|null $nodeFormat = null;
private string|null $nodeEncoding = null;
private int $nodeSize = 0;
public function jsonSerialize(): mixed {
return [
// node meta properties
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
self::JSON_PROPERTY_IN => $this->nodeIn,
self::JSON_PROPERTY_ID => $this->nodeId,
self::JSON_PROPERTY_CREATED_BY => $this->nodeCreatedBy,
self::JSON_PROPERTY_CREATED_ON => $this->nodeCreatedOn?->format('c'),
self::JSON_PROPERTY_MODIFIED_BY => $this->nodeModifiedBy,
self::JSON_PROPERTY_MODIFIED_ON => $this->nodeModifiedOn?->format('c'),
self::JSON_PROPERTY_OWNER => $this->nodeOwner,
self::JSON_PROPERTY_SIGNATURE => $this->nodeSignature,
self::JSON_PROPERTY_SIZE => $this->nodeSize,
// node specific properties
self::JSON_PROPERTY_LABEL => $this->nodeLabel,
self::JSON_PROPERTY_MIME => $this->nodeMime,
self::JSON_PROPERTY_FORMAT => $this->nodeFormat,
self::JSON_PROPERTY_ENCODING => $this->nodeEncoding,
];
}
public function jsonDeserialize(array|string $data): static {
if (is_string($data)) {
$data = json_decode($data, true);
}
// node meta properties
$this->nodeIn = $data[self::JSON_PROPERTY_IN] ?? null;
$this->nodeId = $data[self::JSON_PROPERTY_ID] ?? null;
$this->nodeCreatedBy = $data[self::JSON_PROPERTY_CREATED_BY] ?? null;
$this->nodeCreatedOn = isset($data[self::JSON_PROPERTY_CREATED_ON])
? new DateTimeImmutable($data[self::JSON_PROPERTY_CREATED_ON])
: null;
$this->nodeModifiedBy = $data[self::JSON_PROPERTY_MODIFIED_BY] ?? null;
$this->nodeModifiedOn = isset($data[self::JSON_PROPERTY_MODIFIED_ON])
? new DateTimeImmutable($data[self::JSON_PROPERTY_MODIFIED_ON])
: null;
$this->nodeOwner = $data[self::JSON_PROPERTY_OWNER] ?? null;
$this->nodeSignature = $data[self::JSON_PROPERTY_SIGNATURE] ?? null;
$this->nodeSize = $data[self::JSON_PROPERTY_SIZE] ?? 0;
// node specific properties
$this->nodeLabel = $data[self::JSON_PROPERTY_LABEL] ?? null;
$this->nodeMime = $data[self::JSON_PROPERTY_MIME] ?? null;
$this->nodeFormat = $data[self::JSON_PROPERTY_FORMAT] ?? null;
$this->nodeEncoding = $data[self::JSON_PROPERTY_ENCODING] ?? null;
return $this;
}
public function fromStore(array|object $document): self {
if (is_object($document)) {
$document = (array) $document;
}
// node system properties
$this->tenantId = $document['tid'] ?? null;
$this->userId = $document['uid'] ?? null;
$this->nodeId = $document['nid'] ?? null;
$this->nodeIn = $document['pid'] ?? null;
$this->nodeCreatedBy = $document['createdBy'] ?? null;
$this->nodeCreatedOn = isset($document['createdOn'])
? new DateTimeImmutable($document['createdOn'])
: null;
$this->nodeModifiedBy = $document['modifiedBy'] ?? null;
$this->nodeModifiedOn = isset($document['modifiedOn'])
? new DateTimeImmutable($document['modifiedOn'])
: null;
$this->nodeOwner = $document['owner'] ?? null;
$this->nodeSignature = $document['signature'] ?? md5(json_encode([
$this->nodeId, NodeType::Entity->value, $document['modifiedOn'] ?? ''
]));
$this->nodeSize = $document['size'] ?? 0;
// node specific properties
$this->nodeLabel = $document['label'] ?? null;
$this->nodeMime = $document['mime'] ?? null;
$this->nodeFormat = $document['format'] ?? null;
$this->nodeEncoding = $document['encoding'] ?? null;
return $this;
}
public function toStore(): array {
$now = date('c');
return [
// node system properties
'tid' => $this->tenantId,
'uid' => $this->userId,
'nid' => $this->nodeId,
'pid' => $this->nodeIn,
'type' => NodeType::Entity->value,
'createdBy' => $this->nodeCreatedBy,
'createdOn' => $this->nodeCreatedOn?->format('c') ?? $now,
'modifiedBy' => $this->nodeModifiedBy,
'modifiedOn' => $this->nodeModifiedOn?->format('c') ?? $now,
'owner' => $this->nodeOwner,
'signature' => $this->nodeSignature,
'size' => $this->nodeSize,
// node specific properties
'label' => $this->nodeLabel,
'mime' => $this->nodeMime,
'format' => $this->nodeFormat,
'encoding' => $this->nodeEncoding,
];
}
// Immutable properties
public function in(): string|int|null {
return $this->nodeIn;
}
public function id(): string|int {
return $this->nodeId ?? '';
}
public function type(): NodeType {
return NodeType::Entity;
}
public function createdBy(): string|null {
return $this->nodeCreatedBy;
}
public function createdOn(): DateTimeImmutable|null {
return $this->nodeCreatedOn;
}
public function modifiedBy(): string|null {
return $this->nodeModifiedBy;
}
public function modifiedOn(): DateTimeImmutable|null {
return $this->nodeModifiedOn;
}
public function signature(): string|null {
return $this->nodeSignature;
}
public function size(): int {
return $this->nodeSize;
}
public function isCollection(): bool {
return false;
}
public function isEntity(): bool {
return true;
}
// Mutable properties
public function getLabel(): string|null {
return $this->nodeLabel;
}
public function setLabel(string $value): static {
$this->nodeLabel = $value;
return $this;
}
public function getMime(): string|null {
return $this->nodeMime;
}
public function setMime(string $value): static {
$this->nodeMime = $value;
return $this;
}
public function getFormat(): string|null {
return $this->nodeFormat;
}
public function setFormat(string $value): static {
$this->nodeFormat = $value;
return $this;
}
public function getEncoding(): string|null {
return $this->nodeEncoding;
}
public function setEncoding(string $value): static {
$this->nodeEncoding = $value;
return $this;
}
}

File diff suppressed because it is too large Load Diff