src/Entity/UserDevice.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserDeviceRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassUserDeviceRepository::class)]
  6. #[ORM\UniqueConstraint(name'uniq_user_token'columns: ['token'])]
  7. class UserDevice
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column]
  12.     private ?int $id null;
  13.     #[ORM\ManyToOne(inversedBy'devices')]
  14.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  15.     private ?User $user null;
  16.     #[ORM\Column(length512)]
  17.     private ?string $token null;
  18.     /**
  19.      * web | android | ios | desktop
  20.      */
  21.     #[ORM\Column(length20)]
  22.     private string $platform 'web';
  23.     #[ORM\Column(nullabletrue)]
  24.     private ?\DateTimeImmutable $lastSeenAt null;
  25.     #[ORM\Column]
  26.     private \DateTimeImmutable $createdAt;
  27.     public function __construct()
  28.     {
  29.         $this->createdAt   = new \DateTimeImmutable();
  30.         $this->lastSeenAt  = new \DateTimeImmutable();
  31.     }
  32.     public function getId(): ?int { return $this->id; }
  33.     public function getUser(): ?User { return $this->user; }
  34.     public function setUser(?User $user): static { $this->user $user; return $this; }
  35.     public function getToken(): ?string { return $this->token; }
  36.     public function setToken(string $token): static { $this->token $token; return $this; }
  37.     public function getPlatform(): string { return $this->platform; }
  38.     public function setPlatform(string $platform): static { $this->platform $platform; return $this; }
  39.     public function getLastSeenAt(): ?\DateTimeImmutable { return $this->lastSeenAt; }
  40.     public function setLastSeenAt(\DateTimeImmutable $dt): static { $this->lastSeenAt $dt; return $this; }
  41.     public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
  42.     public function touch(): void
  43.     {
  44.         $this->lastSeenAt = new \DateTimeImmutable();
  45.     }
  46. }