setCreatedAt(new \DateTimeImmutable()); } /** * @ORM\Id * @ORM\Column(type="string", length=255, unique=true) * @ApiProperty(attributes={"openapi_context"={"description" = "Unique hash to identify the secrets"}}) * @Assert\NotNull */ private $hash; /** * @ORM\Column(type="string", length=255) * @ApiProperty(attributes={"openapi_context"={"description" = "The secret itself"}}) * @Assert\NotNull * @Assert\Length( * min = 1, * max = 255 * ) */ private $secretText; /** * @ORM\Column(type="datetime_immutable") * @ApiProperty(attributes={"openapi_context"={"description" = "The date and time of the creation"}}) * @Assert\NotNull */ private $createdAt; /** * @ORM\Column(type="datetime_immutable", nullable=true) * @ApiProperty(attributes={"openapi_context"={"description" = "The secret cannot be reached after this time"}}) */ private $expiresAt; /** * @ORM\Column(type="integer") * @ApiProperty(attributes={"openapi_context"={"description" = "How many times the secret can be viewed"}}) * @Assert\NotNull * @Assert\Range( * min = 0 * ) */ private $remainingViews; public function getHash(): ?string { return $this->hash; } public function getSecretText(): ?string { return $this->secretText; } public function setSecretText(string $secretText): self { $this->secretText = $secretText; $this->hash = md5($secretText . uniqid('dont be too salty please', true)); return $this; } public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } public function setCreatedAt(\DateTimeImmutable $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getExpiresAt(): ?\DateTimeImmutable { return $this->expiresAt; } public function setExpiresAt(?\DateTimeImmutable $expiresAt): self { $this->expiresAt = $expiresAt; return $this; } public function getRemainingViews(): ?int { return $this->remainingViews; } public function setRemainingViews(int $remainingViews): self { $this->remainingViews = $remainingViews; return $this; } }