refactor: standardize design
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
50
lib/Providers/Personal/EntityProperties.php
Normal file
50
lib/Providers/Personal/EntityProperties.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderLocalPeople\Providers\Personal;
|
||||
|
||||
use KTXF\People\Entity\EntityPropertiesMutableAbstract;
|
||||
|
||||
class EntityProperties extends EntityPropertiesMutableAbstract {
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
$data = $this->getDataRaw();
|
||||
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function jsonDeserialize(array|string $data): static {
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
if (is_array($data) && array_key_exists('data', $data)) {
|
||||
$this->setDataRaw($data['data']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->setDataRaw($data);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fromStore(array $data): static {
|
||||
$this->setDataRaw($data['data'] ?? null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toStore(): array {
|
||||
return array_filter([
|
||||
'data' => $this->getDataRaw(),
|
||||
], static fn($value) => $value !== null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user