src/App/Entity/Lock.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Utility\DateTimeUtility;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @ORM\Entity
  8. *
  9. * @ORM\Table(
  10. * name="locks"
  11. * )
  12. */
  13. class Lock
  14. {
  15. public function __construct(string $id, DateTime $createdAt, DateTime $validUntil, ?string $info = null)
  16. {
  17. $this->id = $id;
  18. $this->hashedId = md5($id);
  19. $this->createdAt = $createdAt;
  20. $this->validUntil = $validUntil;
  21. $this->info = $info;
  22. }
  23. /**
  24. * @var string
  25. *
  26. * @ORM\Column(name="id", type="string", length=512)
  27. *
  28. * @ORM\Id
  29. */
  30. protected $id;
  31. public function getId()
  32. {
  33. return $this->id;
  34. }
  35. /**
  36. * It can be hard to manually query for ids in certain cases, thus we add a hashedId that helps with this.
  37. *
  38. * @var string
  39. *
  40. * @ORM\Column(name="hashed_id", type="string", length=32, nullable=true)
  41. */
  42. protected $hashedId;
  43. /**
  44. * @var DateTime
  45. *
  46. * @ORM\Column(name="created_at", type="datetime", nullable=false)
  47. */
  48. protected $createdAt;
  49. public function getCreatedAt(): DateTime
  50. {
  51. return $this->createdAt;
  52. }
  53. /**
  54. * @var DateTime
  55. *
  56. * @ORM\Column(name="valid_until", type="datetime", nullable=false)
  57. */
  58. protected $validUntil;
  59. public function getValidUntil(): DateTime
  60. {
  61. return $this->validUntil;
  62. }
  63. public function isValid(): bool
  64. {
  65. return $this->getValidUntil() > DateTimeUtility::createDateTimeUtc();
  66. }
  67. public function setValidUntil(DateTime $validUntil): void
  68. {
  69. $this->validUntil = $validUntil;
  70. }
  71. /**
  72. * @var ?string
  73. *
  74. * @ORM\Column(name="info", type="text", length=8192, nullable=true)
  75. */
  76. protected $info;
  77. public function getInfo(): ?string
  78. {
  79. return $this->info;
  80. }
  81. public function setInfo(?string $info): void
  82. {
  83. $this->info = $info;
  84. }
  85. }