Files
server/shared/lib/Resource/Provider/Node/NodeMutableAbstract.php
Sebastian Krupinski f3c882454d
All checks were successful
Build Test / build (pull_request) Successful in 12s
JS Unit Tests / test (pull_request) Successful in 11s
PHP Unit Tests / test (pull_request) Successful in 39s
refactor: mail interfaces
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-05-14 22:54:51 -04:00

96 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXF\Resource\Provider\Node;
/**
* Abstract Node Mutable Class
*
* Provides common implementation for mutable resource nodes
*
* @since 2025.05.01
*/
abstract class NodeMutableAbstract extends NodeBaseAbstract implements NodeMutableInterface {
/**
* @inheritDoc
*/
public function jsonDeserialize(array|string $data): static {
if (is_string($data)) {
$data = json_decode($data, true);
}
$this->data = [];
if (isset($data[static::PROPERTY_COLLECTION])) {
if (!is_string($data[static::PROPERTY_COLLECTION]) && !is_int($data[static::PROPERTY_COLLECTION])) {
throw new \InvalidArgumentException("Collection must be a string or integer");
}
$this->data[static::PROPERTY_COLLECTION] = $data[static::PROPERTY_COLLECTION];
} else {
$this->data[static::PROPERTY_COLLECTION] = null;
}
if (isset($data[static::PROPERTY_IDENTIFIER])) {
if (!is_string($data[static::PROPERTY_IDENTIFIER]) && !is_int($data[static::PROPERTY_IDENTIFIER])) {
throw new \InvalidArgumentException("Identifier must be a string or integer");
}
$this->data[static::PROPERTY_IDENTIFIER] = $data[static::PROPERTY_IDENTIFIER];
} else {
$this->data[static::PROPERTY_IDENTIFIER] = null;
}
if (isset($data[static::PROPERTY_SIGNATURE])) {
if (!is_string($data[static::PROPERTY_SIGNATURE]) && !is_int($data[static::PROPERTY_SIGNATURE])) {
throw new \InvalidArgumentException("Signature must be a string or integer");
}
$this->data[static::PROPERTY_SIGNATURE] = $data[static::PROPERTY_SIGNATURE];
} else {
$this->data[static::PROPERTY_SIGNATURE] = null;
}
if (isset($data[static::PROPERTY_CREATED])) {
if (!is_string($data[static::PROPERTY_CREATED])) {
throw new \InvalidArgumentException("Created date must be a string in ISO 8601 format");
}
$this->data[static::PROPERTY_CREATED] = $data[static::PROPERTY_CREATED];
} else {
$this->data[static::PROPERTY_CREATED] = null;
}
if (isset($data[static::PROPERTY_MODIFIED])) {
if (!is_string($data[static::PROPERTY_MODIFIED])) {
throw new \InvalidArgumentException("Modified date must be a string in ISO 8601 format");
}
$this->data[static::PROPERTY_MODIFIED] = $data[static::PROPERTY_MODIFIED];
} else {
$this->data[static::PROPERTY_MODIFIED] = null;
}
if (isset($data[static::PROPERTY_PROPERTIES])) {
if (!is_array($data[static::PROPERTY_PROPERTIES])) {
throw new \InvalidArgumentException("Properties must be an array");
}
$this->getProperties()->jsonDeserialize($data[static::PROPERTY_PROPERTIES]);
}
return $this;
}
/**
* @inheritDoc
*/
abstract public function getProperties(): NodePropertiesMutableInterface;
/**
* @inheritDoc
*/
abstract public function setProperties(NodePropertiesMutableInterface $value): static;
}