src/Entity/BaseEntity.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Ramsey\Uuid\Uuid;
  6. use Ramsey\Uuid\UuidInterface;
  7. #[ORM\MappedSuperclass()]
  8. #[ORM\HasLifecycleCallbacks()]
  9. class BaseEntity
  10. {
  11.     #[ORM\Column(type'datetime')]
  12.     private DateTime $createdAt;
  13.     #[ORM\Column(type'datetime'nullabletrue)]
  14.     private DateTime $updatedAt;
  15.     #[ORM\Column(type'datetime'nullabletrue)]
  16.     private DateTime|null $deletedAt;
  17.     #[ORM\Column(type'string'length255nullabletrue)]
  18.     private string $uuid;
  19.     #[ORM\Column(type'string'length255uniquetruenullabletrue)]
  20.     private string $urlSlug;
  21.     #[ORM\Column(type'text'length160nullabletrue)]
  22.     private string $ogDescription '';
  23.     #[ORM\Column(type'boolean')]
  24.     private bool $active true;
  25.     public function __construct()
  26.     {
  27.         $this->createdAt = new DateTime();
  28.         $this->updatedAt = new DateTime();
  29.         $this->uuid Uuid::uuid4();
  30.         $this->urlSlug uniqid('slug-'false).rand(0,100000000);
  31.     }
  32.     /**
  33.      * @return DateTime
  34.      */
  35.     public function getUpdatedAt(): DateTime
  36.     {
  37.         return $this->updatedAt;
  38.     }
  39.     /**
  40.      * @param DateTime $updatedAt
  41.      */
  42.     public function setUpdatedAt(DateTime $updatedAt): void
  43.     {
  44.         $this->updatedAt $updatedAt;
  45.     }
  46.     /**
  47.      * @return DateTime|null
  48.      */
  49.     public function getDeletedAt(): DateTime|null
  50.     {
  51.         return $this->deletedAt;
  52.     }
  53.     public function setDeletedAt$deletedAt): void
  54.     {
  55.         $this->deletedAt $deletedAt;
  56.     }
  57.     /**
  58.      * @return string
  59.      */
  60.     public function getUrlSlug(): string
  61.     {
  62.         return $this->urlSlug;
  63.     }
  64.     /**
  65.      * @param string $urlSlug
  66.      */
  67.     public function setUrlSlug(string $urlSlug): void
  68.     {
  69.         $this->urlSlug $urlSlug;
  70.     }
  71.     /**
  72.      * @return DateTime
  73.      */
  74.     public function getCreatedAt(): DateTime
  75.     {
  76.         return $this->createdAt;
  77.     }
  78.     /**
  79.      * @param DateTime $createdAt
  80.      */
  81.     public function setCreatedAt(DateTime $createdAt): void
  82.     {
  83.         $this->createdAt $createdAt;
  84.     }
  85.     /**
  86.      * @return string
  87.      */
  88.     public function getUuid(): string
  89.     {
  90.         return $this->uuid;
  91.     }
  92.     /**
  93.      * @param UuidInterface $uuid
  94.      */
  95.     public function setUuid(UuidInterface $uuid): void
  96.     {
  97.         $this->uuid $uuid;
  98.     }
  99.     /**
  100.      * @return bool
  101.      */
  102.     public function isActive(): bool
  103.     {
  104.         return $this->active;
  105.     }
  106.     /**
  107.      * @param bool $active
  108.      */
  109.     public function setActive(bool $active): void
  110.     {
  111.         $this->active $active;
  112.     }
  113.     /**
  114.      * @return string
  115.      */
  116.     public function getOgDescription(): string
  117.     {
  118.         return $this->ogDescription ?: '';
  119.     }
  120.     /**
  121.      * @param string $ogDescription
  122.      */
  123.     public function setOgDescription(string $ogDescription): void
  124.     {
  125.         $this->ogDescription $ogDescription;
  126.     }
  127. }