feat: integrate with MailJet API for newsletter registration

This commit is contained in:
Björn Fromme
2026-03-19 09:42:00 +01:00
parent 66c55f0722
commit d1e2bf3e7d
26 changed files with 1537 additions and 47 deletions
@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\NewsletterOptInConfirmationRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NewsletterOptInConfirmationRepository::class)]
class NewsletterOptInConfirmation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
private string $email;
#[ORM\Column(type: 'string', length: 64, unique: true)]
private string $tokenHash;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $expiresAt;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $confirmedAt = null;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $createdAt;
public function __construct(
string $email,
string $tokenHash,
\DateTimeImmutable $expiresAt,
) {
$this->email = mb_strtolower(trim($email));
$this->tokenHash = $tokenHash;
$this->expiresAt = $expiresAt;
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): string
{
return $this->email;
}
public function getTokenHash(): string
{
return $this->tokenHash;
}
public function getExpiresAt(): \DateTimeImmutable
{
return $this->expiresAt;
}
public function getConfirmedAt(): ?\DateTimeImmutable
{
return $this->confirmedAt;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function isConfirmed(): bool
{
return null !== $this->confirmedAt;
}
public function isExpired(?\DateTimeImmutable $now = null): bool
{
$reference = $now ?? new \DateTimeImmutable();
return $this->expiresAt <= $reference;
}
public function markConfirmed(?\DateTimeImmutable $now = null): void
{
$this->confirmedAt = $now ?? new \DateTimeImmutable();
}
public function refreshRequest(string $tokenHash, \DateTimeImmutable $expiresAt): void
{
$this->tokenHash = $tokenHash;
$this->expiresAt = $expiresAt;
$this->confirmedAt = null;
}
}