From bb035573bc442f51f2a41079e826b5984a6b13dd Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 29 May 2025 19:53:31 -0400 Subject: [PATCH] Add FileAttachmentRecord class for managing file attachment data --- .../Objects/FileAttachmentRecord.php | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/FederationServer/Objects/FileAttachmentRecord.php diff --git a/src/FederationServer/Objects/FileAttachmentRecord.php b/src/FederationServer/Objects/FileAttachmentRecord.php new file mode 100644 index 0000000..46a2a43 --- /dev/null +++ b/src/FederationServer/Objects/FileAttachmentRecord.php @@ -0,0 +1,118 @@ +uuid = $data['uuid'] ?? ''; + $this->evidence = $data['evidence'] ?? ''; + $this->fileName = $data['file_name'] ?? ''; + $this->fileSize = isset($data['file_size']) ? (int)$data['file_size'] : 0; + $this->created = isset($data['created']) ? (int)$data['created'] : time(); + } + + /** + * Get the UUID of the file attachment. + * + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * Get the UUID of the associated evidence record. + * + * @return string + */ + public function getEvidence(): string + { + return $this->evidence; + } + + /** + * Get the name of the file. + * + * @return string + */ + public function getFileName(): string + { + return $this->fileName; + } + + /** + * Get the size of the file in bytes. + * + * @return int + */ + public function getFileSize(): int + { + return $this->fileSize; + } + + /** + * Get the timestamp of when the record was created. + * + * @return int + */ + public function getCreated(): int + { + return $this->created; + } + + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'uuid' => $this->uuid, + 'evidence' => $this->evidence, + 'file_name' => $this->fileName, + 'file_size' => $this->fileSize, + '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