src/Entity/Device.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\DeviceRepository;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping\Column;
  7. use Doctrine\ORM\Mapping\Entity;
  8. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  9. use Doctrine\ORM\Mapping\Id;
  10. use Doctrine\ORM\Mapping\JoinColumn;
  11. use Doctrine\ORM\Mapping\ManyToOne;
  12. use Doctrine\ORM\Mapping\PrePersist;
  13. use Doctrine\ORM\Mapping\PreUpdate;
  14. use Symfony\Component\Uid\Uuid;
  15. #[Entity(DeviceRepository::class)]
  16. #[HasLifecycleCallbacks]
  17. class Device
  18. {
  19.     #[Id]
  20.     #[ManyToOne(targetEntityCreator::class, inversedBy'devices')]
  21.     #[JoinColumn(name'creator_id'onDelete'CASCADE')]
  22.     private Creator $creator;
  23.     #[Id]
  24.     #[Column(type'uuid'name'device_id')]
  25.     private Uuid $deviceId;
  26.     #[Column(type'text'nullabletrue)]
  27.     private ?string $pushToken;
  28.     #[Column(type'string'length50)]
  29.     private string $platform;
  30.     #[Column(type'string'length50)]
  31.     private string $appVersion;
  32.     #[Column(type'string'length50)]
  33.     private string $timezone;
  34.     #[Column('created_at''datetime')]
  35.     private DateTime $createdAt;
  36.     #[Column('updated_at''datetime'nullabletrue)]
  37.     private ?DateTime $updatedAt null;
  38.     public function __construct(
  39.         Creator $creator,
  40.         Uuid $deviceId,
  41.         ?string $pushToken,
  42.         string $platform,
  43.         string $appVersion,
  44.         string $timezone,
  45.     ) {
  46.         $this->creator $creator;
  47.         $this->deviceId $deviceId;
  48.         $this->pushToken $pushToken;
  49.         $this->platform $platform;
  50.         $this->appVersion $appVersion;
  51.         $this->timezone $timezone;
  52.     }
  53.     #[PrePersist]
  54.     public function prePersist(): void
  55.     {
  56.         $this->createdAt = new DateTime();
  57.     }
  58.     #[PreUpdate]
  59.     public function preUpdate(): void
  60.     {
  61.         $this->updatedAt = new DateTime();
  62.     }
  63.     public function getId(): Uuid
  64.     {
  65.         return $this->deviceId;
  66.     }
  67.     public function getDeviceId(): Uuid
  68.     {
  69.         return $this->deviceId;
  70.     }
  71.     public function getPushToken(): ?string
  72.     {
  73.         return $this->pushToken;
  74.     }
  75.     public function getPlatform(): string
  76.     {
  77.         return $this->platform;
  78.     }
  79.     public function getAppVersion(): string
  80.     {
  81.         return $this->appVersion;
  82.     }
  83.     public function getTimezone(): string
  84.     {
  85.         return $this->timezone;
  86.     }
  87.     public function getCreator(): Creator
  88.     {
  89.         return $this->creator;
  90.     }
  91.     public function getCreatedAt(): DateTime
  92.     {
  93.         return $this->createdAt;
  94.     }
  95.     public function getUpdatedAt(): ?DateTime
  96.     {
  97.         return $this->updatedAt;
  98.     }
  99.     public function hasPushToken(): bool
  100.     {
  101.         return $this->pushToken !== null && $this->pushToken !== '';
  102.     }
  103.     public function setPushToken(?string $pushToken): void
  104.     {
  105.         $this->pushToken $pushToken;
  106.     }
  107.     public function setPlatform(string $platform): void
  108.     {
  109.         $this->platform $platform;
  110.     }
  111.     public function setAppVersion(string $appVersion): void
  112.     {
  113.         $this->appVersion $appVersion;
  114.     }
  115.     public function setTimezone(string $timezone): void
  116.     {
  117.         $this->timezone $timezone;
  118.     }
  119. }