src/Entity/InstagramAuth.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Services\Instagram\Dto\InstagramAuthDto;
  4. use DateTimeImmutable;
  5. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  6. use Doctrine\ORM\Mapping\Id;
  7. use Doctrine\ORM\Mapping\Entity;
  8. use Doctrine\ORM\Mapping\Column;
  9. use Doctrine\ORM\Mapping\PrePersist;
  10. use Doctrine\ORM\Mapping\PreUpdate;
  11. #[Entity]
  12. #[HasLifecycleCallbacks]
  13. class InstagramAuth
  14. {
  15.     /**
  16.      * Connected Instagram account for Facebook user.
  17.      * Unique ID of the Instagram business account
  18.      */
  19.     #[Id]
  20.     #[Column(type'bigint'uniquetrue)]
  21.     private int $id;
  22.     /** Instagram ID */
  23.     #[Column(type'bigint'uniquetrue)]
  24.     private int $igId;
  25.     #[Column(type'string')]
  26.     private string $accessToken;
  27.     #[Column(
  28.         type'datetime_immutable',
  29.         nullablefalse,
  30.         columnDefinition'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL',
  31.     )]
  32.     private DateTimeImmutable $refreshedAt;
  33.     #[Column(
  34.         type'datetime_immutable',
  35.         nullabletrue,
  36.         columnDefinition'TIMESTAMP NULL',
  37.     )]
  38.     private DateTimeImmutable $expiresAt;
  39.     #[Column('created_at''datetime_immutable')]
  40.     private ?DateTimeImmutable $createdAt null;
  41.     #[PrePersist]
  42.     public function prePersist(): void
  43.     {
  44.         $this->createdAt = new DateTimeImmutable();
  45.         $this->refreshedAt = new DateTimeImmutable();
  46.     }
  47.     #[PreUpdate]
  48.     public function preUpdate(): void
  49.     {
  50.         $this->refreshedAt = new DateTimeImmutable();
  51.     }
  52.     public function getId(): int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function setId(int $id): static
  57.     {
  58.         $this->id $id;
  59.         return $this;
  60.     }
  61.     public function getIgId(): int
  62.     {
  63.         return $this->igId;
  64.     }
  65.     public function setIgId(int $igId): static
  66.     {
  67.         $this->igId $igId;
  68.         return $this;
  69.     }
  70.     public function getAccessToken(): string
  71.     {
  72.         return $this->accessToken;
  73.     }
  74.     public function setAccessToken(string $accessToken): static
  75.     {
  76.         $this->accessToken $accessToken;
  77.         return $this;
  78.     }
  79.     public function getRefreshedAt(): DateTimeImmutable
  80.     {
  81.         return $this->refreshedAt;
  82.     }
  83.     public function setRefreshedAt(DateTimeImmutable $refreshedAt): static
  84.     {
  85.         $this->refreshedAt $refreshedAt;
  86.         return $this;
  87.     }
  88.     public function setRefreshedAtNow(): static
  89.     {
  90.         $this->refreshedAt = new DateTimeImmutable;
  91.         return $this;
  92.     }
  93.     public function getExpiresAt(): DateTimeImmutable
  94.     {
  95.         return $this->expiresAt;
  96.     }
  97.     public function setExpiresAt(DateTimeImmutable $expiresAt): static
  98.     {
  99.         $this->expiresAt $expiresAt;
  100.         return $this;
  101.     }
  102.     public function getCreatedAt(): ?DateTimeImmutable
  103.     {
  104.         return $this->createdAt;
  105.     }
  106.     public function toDto(): InstagramAuthDto
  107.     {
  108.         return new InstagramAuthDto(
  109.             id$this->getId(),
  110.             igId$this->getIgId(),
  111.             accessToken$this->getAccessToken(),
  112.             refreshedAt$this->getRefreshedAt(),
  113.             expiersAt$this->getExpiresAt(),
  114.             createdAt$this->getCreatedAt()
  115.         );
  116.     }
  117. }