src/JanusHercules/RecurrentJob/Domain/Entity/RecurrentJobAdditionalEmailForApplications.php line 14

Open in your IDE?
  1. <?php
  2. namespace JanusHercules\RecurrentJob\Domain\Entity;
  3. use App\Entity\RecurrentJob;
  4. use App\Service\MailService;
  5. use App\Utility\DatabaseIdGenerator;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use ValueError;
  9. #[ORM\Entity]
  10. #[ORM\Table(name: 'recurrent_job_additional_emails_for_applications')]
  11. class RecurrentJobAdditionalEmailForApplications
  12. {
  13. public function __construct(
  14. RecurrentJob $recurrentJob,
  15. string $email
  16. ) {
  17. $this->recurrentJob = $recurrentJob;
  18. $email = mb_substr($email, 0, 128);
  19. if (!MailService::emailAddressIsValidForMailer($email)) {
  20. throw new ValueError("E-mail '$email' is not valid.");
  21. }
  22. $this->email = $email;
  23. }
  24. #[ORM\Id]
  25. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  26. #[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
  27. #[ORM\Column(
  28. type : Types::GUID,
  29. unique: true
  30. )]
  31. private ?string $id = null;
  32. public function getId(): ?string
  33. {
  34. return $this->id;
  35. }
  36. #[ORM\ManyToOne(
  37. targetEntity: RecurrentJob::class,
  38. cascade : ['persist']
  39. )]
  40. #[ORM\JoinColumn(
  41. name : 'recurrent_jobs_id',
  42. referencedColumnName: 'id',
  43. nullable : false,
  44. onDelete : 'CASCADE'
  45. )]
  46. private RecurrentJob $recurrentJob;
  47. public function getRecurrentJob(): RecurrentJob
  48. {
  49. return $this->recurrentJob;
  50. }
  51. #[ORM\Column(
  52. type : Types::STRING,
  53. length : 128,
  54. nullable: false
  55. )]
  56. private string $email;
  57. public function getEmail(): string
  58. {
  59. return $this->email;
  60. }
  61. }