src/Entity/BaseEntity.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Event\LifecycleEventArgs;
  4. use Doctrine\ORM\Event\OnFlushEventArgs;
  5. use Doctrine\ORM\Event\PreUpdateEventArgs;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\Column;
  8. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  9. use Doctrine\ORM\Mapping\MappedSuperclass;
  10. use Doctrine\ORM\Mapping\Id;
  11. use Doctrine\ORM\Mapping\PrePersist;
  12. use Doctrine\ORM\Mapping\PreRemove;
  13. use Doctrine\ORM\Mapping\PreUpdate;
  14. #[MappedSuperclass]
  15. #[HasLifecycleCallbacks]
  16. class BaseEntity
  17. {
  18.     #[Column(name'uid'type'string'length32)]
  19.     private $uid;
  20.     #[Column(type'datetime')]
  21.     private $dateCreated;
  22.     #[Column(type'datetime')]
  23.     private $dateModified;
  24.     #[Column(type'boolean'nullabletrueoptions:['default' => 1])]
  25.     private $enabled true;
  26.     #[Column(type'boolean'nullabletrueoptions:['default' => 0])]
  27.     private $deleted false;
  28.     public function getDateCreated(): ?\DateTimeInterface
  29.     {
  30.         return $this->dateCreated;
  31.     }
  32.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  33.     {
  34.         $this->dateCreated $dateCreated;
  35.         return $this;
  36.     }
  37.     public function getDateModified(): ?\DateTimeInterface
  38.     {
  39.         return $this->dateModified;
  40.     }
  41.     public function setDateModified(\DateTimeInterface $dateModified): self
  42.     {
  43.         $this->dateModified $dateModified;
  44.         return $this;
  45.     }
  46.     #[PrePersist]
  47.     public function onPrePersist()
  48.     {
  49.         $this->dateCreated = new \DateTime();
  50.         $this->dateModified = new \DateTime();
  51.         $this->uid md5(uniqid() . rand(1999999999999999));
  52.     }
  53.     #[PreRemove]
  54.     public function onPreRemove(LifecycleEventArgs $args)
  55.     {
  56.         $this->dateModified = new \DateTime();
  57.     }
  58.     #[PreUpdate]
  59.     public function onPreUpdate(PreUpdateEventArgs $args)
  60.     {
  61.         $this->dateModified = new \DateTime();
  62.     }
  63.     public function getEnabled(): ?bool
  64.     {
  65.         return $this->enabled;
  66.     }
  67.     public function setEnabled(?bool $enabled): self
  68.     {
  69.         $this->enabled $enabled;
  70.         return $this;
  71.     }
  72.     public function getDeleted(): ?bool
  73.     {
  74.         return $this->deleted;
  75.     }
  76.     public function setDeleted(?bool $deleted): self
  77.     {
  78.         $this->deleted $deleted;
  79.         return $this;
  80.     }
  81.     public function getUid(): ?string
  82.     {
  83.         return $this->uid;
  84.     }
  85.     public function setUid(string $uid): self
  86.     {
  87.         $this->uid $uid;
  88.         return $this;
  89.     }
  90. }