<?php
namespace JanusHercules\RecurrentJob\Domain\Entity;
use App\Entity\RecurrentJob;
use App\Service\MailService;
use App\Utility\DatabaseIdGenerator;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ValueError;
#[ORM\Entity]
#[ORM\Table(name: 'recurrent_job_additional_emails_for_applications')]
class RecurrentJobAdditionalEmailForApplications
{
public function __construct(
RecurrentJob $recurrentJob,
string $email
) {
$this->recurrentJob = $recurrentJob;
$email = mb_substr($email, 0, 128);
if (!MailService::emailAddressIsValidForMailer($email)) {
throw new ValueError("E-mail '$email' is not valid.");
}
$this->email = $email;
}
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[ORM\Column(
type : Types::GUID,
unique: true
)]
private ?string $id = null;
public function getId(): ?string
{
return $this->id;
}
#[ORM\ManyToOne(
targetEntity: RecurrentJob::class,
cascade : ['persist']
)]
#[ORM\JoinColumn(
name : 'recurrent_jobs_id',
referencedColumnName: 'id',
nullable : false,
onDelete : 'CASCADE'
)]
private RecurrentJob $recurrentJob;
public function getRecurrentJob(): RecurrentJob
{
return $this->recurrentJob;
}
#[ORM\Column(
type : Types::STRING,
length : 128,
nullable: false
)]
private string $email;
public function getEmail(): string
{
return $this->email;
}
}