refactor: use unified provider desing
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
namespace KTXM\ProviderLocalPeople\Providers\Personal;
|
||||
|
||||
use KTXF\People\Collection\CollectionMutableAbstract;
|
||||
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||
|
||||
class CollectionResource extends CollectionMutableAbstract {
|
||||
|
||||
@@ -24,6 +25,14 @@ class CollectionResource extends CollectionMutableAbstract {
|
||||
parent::__construct($provider, $service);
|
||||
}
|
||||
|
||||
protected function nodeIdentifier(): CollectionIdentifier {
|
||||
return new CollectionIdentifier(
|
||||
$this->data[static::PROPERTY_PROVIDER],
|
||||
$this->data[static::PROPERTY_SERVICE],
|
||||
(string) $this->data[static::PROPERTY_IDENTIFIER]
|
||||
);
|
||||
}
|
||||
|
||||
public function fromStore(array|object $data): self
|
||||
{
|
||||
if (is_object($data)) {
|
||||
@@ -31,23 +40,23 @@ class CollectionResource extends CollectionMutableAbstract {
|
||||
}
|
||||
|
||||
if (isset($data['cid'])) {
|
||||
$this->data[self::JSON_PROPERTY_IDENTIFIER] = (string) $data['cid'];
|
||||
$this->data[self::PROPERTY_IDENTIFIER] = (string) $data['cid'];
|
||||
} elseif (isset($data['_id'])) {
|
||||
if (is_object($data['_id']) && method_exists($data['_id'], '__toString')) {
|
||||
$this->data[self::JSON_PROPERTY_IDENTIFIER] = (string) $data['_id'];
|
||||
$this->data[self::PROPERTY_IDENTIFIER] = (string) $data['_id'];
|
||||
} elseif (is_array($data['_id']) && isset($data['_id']['$oid'])) {
|
||||
$this->data[self::JSON_PROPERTY_IDENTIFIER] = (string) $data['_id']['$oid'];
|
||||
$this->data[self::PROPERTY_IDENTIFIER] = (string) $data['_id']['$oid'];
|
||||
} else {
|
||||
$this->data[self::JSON_PROPERTY_IDENTIFIER] = (string) $data['_id'];
|
||||
$this->data[self::PROPERTY_IDENTIFIER] = (string) $data['_id'];
|
||||
}
|
||||
}
|
||||
$this->userId = $data['uid'] ?? null;
|
||||
$this->collectionUuid = isset($data['uuid']) ? (string) $data['uuid'] : null;
|
||||
$this->getProperties()->fromStore($data);
|
||||
$this->data[self::JSON_PROPERTY_CREATED] = $data['createdOn'] ?? $data['created'] ?? null;
|
||||
$this->data[self::JSON_PROPERTY_MODIFIED] = $data['modifiedOn'] ?? $data['modified'] ?? null;
|
||||
$this->data[self::PROPERTY_CREATED] = $data['createdOn'] ?? $data['created'] ?? null;
|
||||
$this->data[self::PROPERTY_MODIFIED] = $data['modifiedOn'] ?? $data['modified'] ?? null;
|
||||
$this->collectionEnabled = $data['enabled'] ?? true;
|
||||
$this->data[self::JSON_PROPERTY_SIGNATURE] = isset($data['signature']) ? md5((string) $data['signature']) : null;
|
||||
$this->data[self::PROPERTY_SIGNATURE] = isset($data['signature']) ? md5((string) $data['signature']) : null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -61,12 +70,12 @@ class CollectionResource extends CollectionMutableAbstract {
|
||||
'uuid' => $this->collectionUuid,
|
||||
'label' => $properties->getLabel(),
|
||||
'description' => $properties->getDescription(),
|
||||
'priority' => $properties->getPriority(),
|
||||
'rank' => $properties->getRank(),
|
||||
'visibility' => $properties->getVisibility(),
|
||||
'color' => $properties->getColor(),
|
||||
'createdOn' => $this->data[self::JSON_PROPERTY_CREATED] ?? null,
|
||||
'modifiedOn' => $this->data[self::JSON_PROPERTY_MODIFIED] ?? null,
|
||||
'signature' => $this->data[self::JSON_PROPERTY_SIGNATURE] ?? null,
|
||||
'createdOn' => $this->data[self::PROPERTY_CREATED] ?? null,
|
||||
'modifiedOn' => $this->data[self::PROPERTY_MODIFIED] ?? null,
|
||||
'signature' => $this->data[self::PROPERTY_SIGNATURE] ?? null,
|
||||
'enabled' => $this->collectionEnabled,
|
||||
], static fn($value) => $value !== null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user