From 3d4a99b6a71f16449074943fa2a62e3d74f61420 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 29 May 2025 20:00:33 -0400 Subject: [PATCH] Add EntityRecord class for managing entity data and serialization --- src/FederationServer/Objects/EntityRecord.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/FederationServer/Objects/EntityRecord.php diff --git a/src/FederationServer/Objects/EntityRecord.php b/src/FederationServer/Objects/EntityRecord.php new file mode 100644 index 0000000..37c2d5d --- /dev/null +++ b/src/FederationServer/Objects/EntityRecord.php @@ -0,0 +1,103 @@ +uuid = $data['uuid'] ?? ''; + $this->id = $data['id'] ?? ''; + $this->domain = $data['domain'] ?? ''; + $this->created = isset($data['created']) ? (int)$data['created'] : time(); + } + + /** + * Get the UUID of the entity. + * + * @return string The UUID of the entity. + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * Get the unique identifier of the entity. + * + * @return string The unique identifier of the entity. + */ + public function getId(): string + { + return $this->id; + } + + /** + * Get the domain associated with the entity. + * + * @return string The domain of the entity. + */ + public function getDomain(): string + { + return $this->domain; + } + + /** + * Get the creation timestamp of the entity record. + * + * @return int The timestamp when the record was created. + */ + public function getCreated(): int + { + return $this->created; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'uuid' => $this->uuid, + 'id' => $this->id, + 'domain' => $this->domain, + 'created' => $this->created, + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(array $array): SerializableInterface + { + if(isset($array['created'])) + { + if(is_string($array['created))'])) + { + $array['created'] = strtotime($array['created']); + } + elseif($array['created'] instanceof \DateTime) + { + $array['created'] = $array['created']->getTimestamp(); + } + } + + return new self($array); + } + } \ No newline at end of file