refactor: documents
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
31
shared/lib/Resource/Documents/Entity/EntityBaseAbstract.php
Normal file
31
shared/lib/Resource/Documents/Entity/EntityBaseAbstract.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeBaseAbstract;
|
||||
|
||||
/**
|
||||
* Abstract Chrono Entity Base Class
|
||||
*
|
||||
* Provides common implementation for chrono entities
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
abstract class EntityBaseAbstract extends NodeBaseAbstract implements EntityBaseInterface {
|
||||
|
||||
protected EntityPropertiesBaseAbstract $properties;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties(): EntityPropertiesBaseInterface {
|
||||
return $this->properties;
|
||||
}
|
||||
}
|
||||
25
shared/lib/Resource/Documents/Entity/EntityBaseInterface.php
Normal file
25
shared/lib/Resource/Documents/Entity/EntityBaseInterface.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeBaseInterface;
|
||||
|
||||
interface EntityBaseInterface extends NodeBaseInterface {
|
||||
|
||||
public const JSON_TYPE = 'document:entity';
|
||||
|
||||
/**
|
||||
* Gets the entity properties
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getProperties(): EntityPropertiesBaseInterface|EntityPropertiesMutableInterface;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeMutableAbstract;
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
||||
|
||||
/**
|
||||
* Abstract Chrono Entity Mutable Class
|
||||
*
|
||||
* Provides common implementation for mutable chrono entities
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
abstract class EntityMutableAbstract extends NodeMutableAbstract implements EntityMutableInterface {
|
||||
|
||||
public const JSON_TYPE = EntityMutableInterface::JSON_TYPE;
|
||||
|
||||
protected EntityPropertiesMutableAbstract $properties;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties(): EntityPropertiesMutableInterface {
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setProperties(NodePropertiesMutableInterface $value): static {
|
||||
if (!$value instanceof EntityPropertiesMutableInterface) {
|
||||
throw new \InvalidArgumentException('Properties must implement EntityPropertiesMutableInterface');
|
||||
}
|
||||
|
||||
$this->properties->setDataRaw($value->getDataRaw());
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeMutableInterface;
|
||||
|
||||
/**
|
||||
* @method static setProperties(EntityPropertiesMutableInterface $value)
|
||||
*/
|
||||
interface EntityMutableInterface extends EntityBaseInterface, NodeMutableInterface {
|
||||
|
||||
public const JSON_TYPE = EntityBaseInterface::JSON_TYPE;
|
||||
|
||||
/**
|
||||
* Gets the entity properties (mutable)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getProperties(): EntityPropertiesMutableInterface;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesBaseAbstract;
|
||||
|
||||
abstract class EntityPropertiesBaseAbstract extends NodePropertiesBaseAbstract implements EntityPropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = EntityPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
public function size(): int {
|
||||
return $this->data[self::JSON_PROPERTY_SIZE] ?? 0;
|
||||
}
|
||||
|
||||
public function getLabel(): string {
|
||||
return $this->data[self::JSON_PROPERTY_LABEL] ?? '';
|
||||
}
|
||||
|
||||
public function getMime(): string {
|
||||
return $this->data[self::JSON_PROPERTY_MIME] ?? '';
|
||||
}
|
||||
|
||||
public function getFormat(): string {
|
||||
return $this->data[self::JSON_PROPERTY_FORMAT] ?? '';
|
||||
}
|
||||
|
||||
public function getEncoding(): string {
|
||||
return $this->data[self::JSON_PROPERTY_ENCODING] ?? '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesBaseInterface;
|
||||
|
||||
interface EntityPropertiesBaseInterface extends NodePropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = 'document:file';
|
||||
public const JSON_PROPERTY_LABEL = 'label';
|
||||
public const JSON_PROPERTY_SIZE = 'size';
|
||||
public const JSON_PROPERTY_MIME = 'mime';
|
||||
public const JSON_PROPERTY_FORMAT = 'format';
|
||||
public const JSON_PROPERTY_ENCODING = 'encoding';
|
||||
|
||||
public function size(): int;
|
||||
|
||||
public function getLabel(): string;
|
||||
|
||||
public function getMime(): string;
|
||||
|
||||
public function getFormat(): string;
|
||||
|
||||
public function getEncoding(): string;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
abstract class EntityPropertiesMutableAbstract extends EntityPropertiesBaseAbstract implements EntityPropertiesMutableInterface {
|
||||
|
||||
public const JSON_TYPE = EntityPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
public function jsonDeserialize(array|string $data): static {
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLabel(string $value): static {
|
||||
$this->data[self::JSON_PROPERTY_LABEL] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMime(string $value): static {
|
||||
$this->data[self::JSON_PROPERTY_MIME] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFormat(string $value): static {
|
||||
$this->data[self::JSON_PROPERTY_FORMAT] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEncoding(string $value): static {
|
||||
$this->data[self::JSON_PROPERTY_ENCODING] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Resource\Documents\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
||||
|
||||
interface EntityPropertiesMutableInterface extends EntityPropertiesBaseInterface, NodePropertiesMutableInterface {
|
||||
|
||||
public const JSON_TYPE = EntityPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
public function setLabel(string $value): static;
|
||||
|
||||
public function setMime(string $value): static;
|
||||
|
||||
public function setFormat(string $value): static;
|
||||
|
||||
public function setEncoding(string $value): static;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user