Files
myep/src/Entity/LogEntry.php
T

154 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\LogEntryRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: LogEntryRepository::class)]
#[ORM\Index(name: 'IDX_LOG_ENTRY_ERROR_CODE', columns: ['error_code'])]
class LogEntry
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $channel;
#[ORM\Column(type: 'string', length: 255)]
private ?string $message;
/**
* @var array<string, mixed>|null
*/
#[ORM\Column(type: 'json', nullable: true)]
private ?array $context = [];
/**
* @var array<string, mixed>|null
*/
#[ORM\Column(type: 'json', nullable: true)]
private ?array $extra = [];
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $createdAt;
#[ORM\Column(type: 'string', length: 12, nullable: true)]
private ?string $errorCode = null;
public function __construct(string $channel, string $message)
{
$this->channel = $channel;
$this->message = $message;
$this->createdAt = new \DateTimeImmutable('now');
}
public function getId(): ?int
{
return $this->id;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function getChannel(): ?string
{
return $this->channel;
}
public function setChannel(?string $channel): self
{
$this->channel = $channel;
return $this;
}
/**
* @return array<string, mixed>|null
*/
public function getContext(): ?array
{
return $this->context;
}
/**
* @param array<string, mixed>|null $context
*/
public function setContext(?array $context): self
{
$this->context = $context;
return $this;
}
/**
* @return array<string, mixed>|null
*/
public function getExtra(): ?array
{
return $this->extra;
}
/**
* @param array<string, mixed>|null $extra
*/
public function setExtra(?array $extra): self
{
$this->extra = $extra;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUsername(): string
{
return $this->getExtra()['user']['username'] ?? '';
}
public function getRequestId(): string
{
return $this->getExtra()['request_id'] ?? '-';
}
public function getErrorCode(): ?string
{
return $this->errorCode;
}
public function setErrorCode(?string $errorCode): self
{
$this->errorCode = $errorCode;
return $this;
}
public function getUri(): string
{
return $this->getExtra()['uri'] ?? '';
}
}