src/Entity/Log.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use App\Traits\UuidEntityTrait;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity
  12.  * @ORM\Table(name="log", indexes={
  13.  *  @ORM\Index(name="idx_log_created_at", columns={"created_at"}), 
  14.  *  @ORM\Index(name="idx_log_level", columns={"level"})
  15.  * })
  16.  * @ORM\HasLifecycleCallbacks
  17.  */
  18. #[ApiResource(
  19.     collectionOperations: ['get'],
  20.     itemOperations: ['get']
  21. )]
  22. #[ApiFilter(SearchFilter::class, properties: [
  23.     'context' => SearchFilter::STRATEGY_PARTIAL,
  24.     'message' => SearchFilter::STRATEGY_PARTIAL,
  25. ])]
  26. #[ApiFilter(DateFilter::class, properties: ['createdAt'])]
  27. #[ApiFilter(OrderFilter::class, properties: ['createdAt' => 'DESC'])]
  28. class Log
  29. {
  30.     use UuidEntityTrait;
  31.     /**
  32.      * @ORM\Column(name="message", type="text")
  33.      */
  34.     private ?string $message null;
  35.     /**
  36.      * @ORM\Column(name="context", type="array")
  37.      */
  38.     private ?array $context null;
  39.     /**
  40.      * @ORM\Column(name="level", type="smallint")
  41.      */
  42.     private ?int $level null;
  43.     /**
  44.      * @ORM\Column(name="level_name", type="string", length=50)
  45.      */
  46.     private ?string $levelName null;
  47.     /**
  48.      * @ORM\Column(name="extra", type="array")
  49.      */
  50.     private ?array $extra null;
  51.     /**
  52.      * @ORM\Column(name="created_at", type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  53.      */
  54.     private ?\DateTimeInterface $createdAt null;
  55.     /**
  56.      * @ORM\PrePersist
  57.      */
  58.     public function onPrePersist()
  59.     {
  60.         $this->createdAt = new \DateTime();
  61.     }
  62.     public function getMessage(): ?string
  63.     {
  64.         return $this->message;
  65.     }
  66.     public function setMessage(string $message): Log
  67.     {
  68.         $this->message $message;
  69.         return $this;
  70.     }
  71.     public function getContext(): ?array
  72.     {
  73.         return $this->context;
  74.     }
  75.     public function setContext(array $context): Log
  76.     {
  77.         $this->context $context;
  78.         return $this;
  79.     }
  80.     public function getLevel(): ?int
  81.     {
  82.         return $this->level;
  83.     }
  84.     public function setLevel(int $level): Log
  85.     {
  86.         $this->level $level;
  87.         return $this;
  88.     }
  89.     public function getLevelName(): ?string
  90.     {
  91.         return $this->levelName;
  92.     }
  93.     public function setLevelName(string $levelName): Log
  94.     {
  95.         $this->levelName $levelName;
  96.         return $this;
  97.     }
  98.     public function getExtra(): ?array
  99.     {
  100.         return $this->extra;
  101.     }
  102.     public function setExtra(array $extra): Log
  103.     {
  104.         $this->extra $extra;
  105.         return $this;
  106.     }
  107.     public function getCreatedAt(): ?\DateTimeInterface
  108.     {
  109.         return $this->createdAt;
  110.     }
  111.     public function setCreatedAt(\DateTimeInterface $createdAt): Log
  112.     {
  113.         $this->createdAt $createdAt;
  114.         return $this;
  115.     }
  116. }