Added AuditLogType and AuditLogRecord
Some checks are pending
CI / debug (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / release (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions

This commit is contained in:
netkas 2025-05-29 20:10:16 -04:00
parent 3d4a99b6a7
commit 857b1d8ddf
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,8 @@
<?php
namespace FederationServer\Classes\Enums;
enum AuditLogType : string
{
case OTHER = 'OTHER';
}

View file

@ -0,0 +1,131 @@
<?php
namespace FederationServer\Objects;
use FederationServer\Classes\Enums\AuditLogType;
use FederationServer\Interfaces\SerializableInterface;
class AuditLogRecord implements SerializableInterface
{
private string $uuid;
private ?string $operator;
private ?string $entity;
private AuditLogType $type;
private string $message;
private int $timestamp;
/**
* AuditLogRecord constructor.
*
* @param array $data Associative array of audit log data.
*/
public function __construct(array $data)
{
$this->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);
}
}