From 857b1d8ddff387efd9867a59a872163d1cd6e390 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 29 May 2025 20:10:16 -0400 Subject: [PATCH] Added AuditLogType and AuditLogRecord --- .../Classes/Enums/AuditLogType.php | 8 ++ .../Objects/AuditLogRecord.php | 131 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 src/FederationServer/Classes/Enums/AuditLogType.php create mode 100644 src/FederationServer/Objects/AuditLogRecord.php diff --git a/src/FederationServer/Classes/Enums/AuditLogType.php b/src/FederationServer/Classes/Enums/AuditLogType.php new file mode 100644 index 0000000..bb785e5 --- /dev/null +++ b/src/FederationServer/Classes/Enums/AuditLogType.php @@ -0,0 +1,8 @@ +uuid = $data['uuid'] ?? ''; + $this->operator = $data['operator'] ?? null; + $this->entity = $data['entity'] ?? null; + $this->type = isset($data['type']) ? AuditLogType::from($data['type']) : AuditLogType::OTHER; + $this->message = $data['message'] ?? ''; + $this->timestamp = isset($data['timestamp']) ? (int)$data['timestamp'] : time(); + } + + /** + * Get the UUID of the audit log record. + * + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * Get the operator UUID associated with the audit log record. + * + * @return string|null + */ + public function getOperator(): ?string + { + return $this->operator; + } + + /** + * Get the entity associated with the audit log record. + * + * @return string|null + */ + public function getEntity(): ?string + { + return $this->entity; + } + + /** + * Get the type of the audit log record. + * + * @return AuditLogType + */ + public function getType(): AuditLogType + { + return $this->type; + } + + /** + * Get the message of the audit log record. + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Get the timestamp of the audit log record. + * + * @return int + */ + public function getTimestamp(): int + { + return $this->timestamp; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'uuid' => $this->uuid, + 'operator' => $this->operator, + 'entity' => $this->entity, + 'type' => $this->type->value, + 'message' => $this->message, + 'timestamp' => $this->timestamp, + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(array $array): SerializableInterface + { + if(isset($array['timestamp'])) + { + if(is_string($array['timestamp'])) + { + $array['timestamp'] = strtotime($array['timestamp']); + } + elseif($array['timestamp'] instanceof \DateTime) + { + $array['timestamp'] = $array['timestamp']->getTimestamp(); + } + } + + if(isset($array['type']) && is_string($array['type'])) + { + $array['type'] = AuditLogType::from($array['type']); + } + + return new self($array); + } + } \ No newline at end of file