refactor: people provider
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
31
shared/lib/People/Entity/EntityBaseAbstract.php
Normal file
31
shared/lib/People/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\People\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeBaseAbstract;
|
||||
|
||||
/**
|
||||
* Abstract Entity Base Class
|
||||
*
|
||||
* Provides common implementation for 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/People/Entity/EntityBaseInterface.php
Normal file
25
shared/lib/People/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\People\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeBaseInterface;
|
||||
|
||||
interface EntityBaseInterface extends NodeBaseInterface {
|
||||
|
||||
public const JSON_TYPE = 'people:entity';
|
||||
|
||||
/**
|
||||
* Gets the entity properties
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getProperties(): EntityPropertiesBaseInterface|EntityPropertiesMutableInterface;
|
||||
|
||||
}
|
||||
47
shared/lib/People/Entity/EntityMutableAbstract.php
Normal file
47
shared/lib/People/Entity/EntityMutableAbstract.php
Normal file
@@ -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\People\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeMutableAbstract;
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
||||
|
||||
/**
|
||||
* Abstract Entity Mutable Class
|
||||
*
|
||||
* Provides common implementation for mutable 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;
|
||||
}
|
||||
}
|
||||
28
shared/lib/People/Entity/EntityMutableInterface.php
Normal file
28
shared/lib/People/Entity/EntityMutableInterface.php
Normal file
@@ -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\People\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;
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\Entity;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
enum EntityPermissions: string implements JsonSerializable {
|
||||
|
||||
case View = 'view';
|
||||
case Modify = 'modify';
|
||||
case Delete = 'delete';
|
||||
case Share = 'share';
|
||||
|
||||
public function jsonSerialize(): string {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
21
shared/lib/People/Entity/EntityPropertiesBaseAbstract.php
Normal file
21
shared/lib/People/Entity/EntityPropertiesBaseAbstract.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesBaseAbstract;
|
||||
|
||||
abstract class EntityPropertiesBaseAbstract extends NodePropertiesBaseAbstract implements EntityPropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = EntityPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
public function getDataRaw(): array|string|null {
|
||||
return $this->data[self::JSON_PROPERTY_DATA] ?? null;
|
||||
}
|
||||
}
|
||||
21
shared/lib/People/Entity/EntityPropertiesBaseInterface.php
Normal file
21
shared/lib/People/Entity/EntityPropertiesBaseInterface.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesBaseInterface;
|
||||
|
||||
interface EntityPropertiesBaseInterface extends NodePropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = 'people:entity';
|
||||
public const JSON_PROPERTY_DATA = 'data';
|
||||
|
||||
public function getDataRaw(): array|string|null;
|
||||
|
||||
}
|
||||
30
shared/lib/People/Entity/EntityPropertiesMutableAbstract.php
Normal file
30
shared/lib/People/Entity/EntityPropertiesMutableAbstract.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\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 setDataRaw(array|string|null $value): static {
|
||||
$this->data[self::JSON_PROPERTY_DATA] = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\Entity;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
||||
|
||||
interface EntityPropertiesMutableInterface extends EntityPropertiesBaseInterface, NodePropertiesMutableInterface {
|
||||
|
||||
public const JSON_TYPE = EntityPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
public function setDataRaw(array|string|null $value): static;
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\Entity;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use KTXF\People\Entity\Individual\IndividualObject;
|
||||
|
||||
interface IEntityBase extends \JsonSerializable {
|
||||
|
||||
public const JSON_TYPE = 'people.entity';
|
||||
public const JSON_PROPERTY_TYPE = '@type';
|
||||
public const JSON_PROPERTY_IN = 'in';
|
||||
public const JSON_PROPERTY_ID = 'id';
|
||||
public const JSON_PROPERTY_DATA = 'data';
|
||||
public const JSON_PROPERTY_CREATED = 'created';
|
||||
public const JSON_PROPERTY_MODIFIED = 'modified';
|
||||
public const JSON_PROPERTY_SIGNATURE = 'signature';
|
||||
|
||||
/**
|
||||
* Unique arbitrary text string identifying the collection this entity belongs to (e.g. 1 or Collection1 or anything else)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function in(): string|int;
|
||||
|
||||
/**
|
||||
* Unique arbitrary text string identifying this service (e.g. 1 or Entity or anything else)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function id(): string|int;
|
||||
|
||||
/**
|
||||
* Gets the creation date of this entity
|
||||
*/
|
||||
public function created(): ?DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* Gets the modification date of this entity
|
||||
*/
|
||||
public function modified(): ?DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* Gets the signature of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function signature(): ?string;
|
||||
|
||||
/**
|
||||
* Gets the priority of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getPriority(): ?int;
|
||||
|
||||
/**
|
||||
* Gets the visibility of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getVisibility(): ?bool;
|
||||
|
||||
/**
|
||||
* Gets the color of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getColor(): ?string;
|
||||
|
||||
/**
|
||||
* Gets the object as a class instance.
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getDataObject(): IndividualObject|null;
|
||||
|
||||
/**
|
||||
* Gets the raw data as an associative array or JSON string.
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return array|string|null
|
||||
*/
|
||||
public function getDataJson(): array|string|null;
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\People\Entity;
|
||||
|
||||
use KTXF\Json\JsonDeserializable;
|
||||
use KTXF\People\Entity\Individual\IndividualObject;
|
||||
|
||||
interface IEntityMutable extends IEntityBase, JsonDeserializable {
|
||||
|
||||
/**
|
||||
* Sets the priority of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function setPriority(?int $value): static;
|
||||
|
||||
/**
|
||||
* Sets the visibility of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function setVisibility(?bool $value): static;
|
||||
|
||||
/**
|
||||
* Sets the color of this entity
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function setColor(?string $value): static;
|
||||
|
||||
/**
|
||||
* Sets the object as a class instance.
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function setDataObject(IndividualObject $value): static;
|
||||
|
||||
/**
|
||||
* Sets the object data from a json string
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function setDataJson(array|string $value): static;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user