src/FlexApp/DTO/LogMessageDto.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace FlexApp\DTO;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use JsonSerializable;
  7. use Monolog\Logger;
  8. use Monolog\Logger as MessageLevel;
  9. class LogMessageDto implements JsonSerializable
  10. {
  11.     private string $app;
  12.     private DateTimeInterface $createdAt;
  13.     private string $message;
  14.     private string $messageLevel;
  15.     private string $job;
  16.     public function __construct(
  17.         string $message,
  18.         string $messageLevel,
  19.         string $job,
  20.         string $app
  21.     ) {
  22.         $this->setApplication($app);
  23.         $this->setMessage($message);
  24.         $this->setMessageLevel($messageLevel);
  25.         $this->setJob($job);
  26.         $this->createdAt = new DateTime();
  27.     }
  28.     public function getApplication(): string
  29.     {
  30.         return $this->app;
  31.     }
  32.     public function setApplication(string $app): void
  33.     {
  34.         $this->app $app;
  35.     }
  36.     public function getCreatedAt(): DateTime
  37.     {
  38.         return $this->createdAt;
  39.     }
  40.     public function getMessage(): string
  41.     {
  42.         return $this->message;
  43.     }
  44.     public function setMessage(string $message): void
  45.     {
  46.         $this->message $message;
  47.     }
  48.     public function getMessageLevel(): string
  49.     {
  50.         return $this->messageLevel;
  51.     }
  52.     public function setMessageLevel(string $messageLevel): void
  53.     {
  54.         $normalized strtoupper($messageLevel);
  55.         if (!in_array($normalizedLogger::getLevels(), true)) {
  56.             $messageLevel mb_strtolower(Logger::getLevelName(MessageLevel::INFO));
  57.         }
  58.         $this->messageLevel $messageLevel;
  59.     }
  60.     public function jsonSerialize(): array
  61.     {
  62.         return [
  63.             'app' => $this->app,
  64.             'job' => $this->job,
  65.             'message' => $this->message,
  66.             'messageLevel' => $this->messageLevel,
  67.             'createdAt' => $this->createdAt->format(DateTimeInterface::ATOM),
  68.         ];
  69.     }
  70.     public function getJob(): string
  71.     {
  72.         return $this->job;
  73.     }
  74.     public function setJob(string $job): void
  75.     {
  76.         $this->job $job;
  77.     }
  78. }