src/Entity/OTP.php line 10

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OTPRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassOTPRepository::class)]
  7. class OTP
  8. {
  9.     const TYPE_USER 'TYPE_USER';
  10.     const TYPE_WALLET 'TYPE_WALLET';
  11.     const TYPE_WITHDRAWAL 'TYPE_WITHDRAWAL';
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $pass null;
  18.     #[ORM\Column]
  19.     private ?DateTimeImmutable $expiredAt null;
  20.     #[ORM\ManyToOne(inversedBy'OTPs')]
  21.     #[ORM\JoinColumn(nullablefalse)]
  22.     private ?User $user null;
  23.     #[ORM\Column(length255)]
  24.     private ?string $type null;
  25.     #[ORM\Column(length15)]
  26.     private ?string $phone null;
  27.     #[ORM\Column]
  28.     private ?int $typeId null;
  29.     public static function generate(User $user$n 4$minutes 1$type self::TYPE_USER$phone null$typeId null)
  30.     {
  31.         $generator "1357902468";
  32.         $result "";
  33.         for ($i 1$i <= $n$i++) {
  34.             $result .= $generator[(mt_rand() % (strlen($generator)))];
  35.         }
  36.         return (new self())
  37.             ->setUser($user)
  38.             ->setPass($result)
  39.             ->setType($type)
  40.             ->setTypeId($typeId)
  41.             ->setPhone($phone)
  42.             ->setExpiredAt((new DateTimeImmutable())->modify("+$minutes minutes"));
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getPass(): ?string
  49.     {
  50.         return $this->pass;
  51.     }
  52.     public function setPass(string $pass): self
  53.     {
  54.         $this->pass $pass;
  55.         return $this;
  56.     }
  57.     public function getExpiredAt(): ?DateTimeImmutable
  58.     {
  59.         return $this->expiredAt;
  60.     }
  61.     public function setExpiredAt(DateTimeImmutable $expiredAt): self
  62.     {
  63.         $this->expiredAt $expiredAt;
  64.         return $this;
  65.     }
  66.     public function getUser(): ?User
  67.     {
  68.         return $this->user;
  69.     }
  70.     public function setUser(?User $user): self
  71.     {
  72.         $this->user $user;
  73.         return $this;
  74.     }
  75.     public function getType(): ?string
  76.     {
  77.         return $this->type;
  78.     }
  79.     public function setType(string $type): self
  80.     {
  81.         $this->type $type;
  82.         return $this;
  83.     }
  84.     public function getPhone(): ?string
  85.     {
  86.         return $this->phone;
  87.     }
  88.     public function setPhone(string $phone): self
  89.     {
  90.         $this->phone $phone;
  91.         return $this;
  92.     }
  93.     public function getTypeId(): ?int
  94.     {
  95.         return $this->typeId;
  96.     }
  97.     public function setTypeId(int $typeId): self
  98.     {
  99.         $this->typeId $typeId;
  100.         return $this;
  101.     }
  102. }