src/Entity/SsoEmailInstanceMapping.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\SsoEmailInstanceMappingRepository;
  5. use DateTimeImmutable;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=SsoEmailInstanceMappingRepository::class)
  9.  * @ORM\Table(
  10.  *     name="sso_email_instance_mapping",
  11.  *     uniqueConstraints={
  12.  *         @ORM\UniqueConstraint(
  13.  *             name="uniq_sso_email_instance_mapping_normalized_email",
  14.  *             columns={"normalized_email"}
  15.  *         )
  16.  *     },
  17.  *     indexes={
  18.  *         @ORM\Index(
  19.  *             name="idx_sso_email_instance_mapping_instance",
  20.  *             columns={"instance_id"}
  21.  *         )
  22.  *     }
  23.  * )
  24.  * @ORM\HasLifecycleCallbacks
  25.  */
  26. class SsoEmailInstanceMapping
  27. {
  28.     /**
  29.      * @ORM\Id
  30.      * @ORM\GeneratedValue
  31.      * @ORM\Column(type="integer")
  32.      */
  33.     private ?int $id null;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private string $email;
  38.     /**
  39.      * @ORM\Column(name="normalized_email", type="string", length=255, unique=true)
  40.      */
  41.     private string $normalizedEmail;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=Instance::class)
  44.      * @ORM\JoinColumn(name="instance_id", nullable=false, onDelete="CASCADE")
  45.      */
  46.     private ?Instance $instance null;
  47.     /**
  48.      * @ORM\Column(name="source_organization_label", type="string", length=255)
  49.      */
  50.     private string $sourceOrganizationLabel;
  51.     /**
  52.      * @ORM\Column(name="created_at", type="datetime_immutable")
  53.      */
  54.     private DateTimeImmutable $createdAt;
  55.     /**
  56.      * @ORM\Column(name="updated_at", type="datetime_immutable")
  57.      */
  58.     private DateTimeImmutable $updatedAt;
  59.     public function __construct()
  60.     {
  61.         $now = new DateTimeImmutable();
  62.         $this->createdAt $now;
  63.         $this->updatedAt $now;
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getEmail(): string
  70.     {
  71.         return $this->email;
  72.     }
  73.     public function setEmail(string $email): self
  74.     {
  75.         $this->email trim($email);
  76.         return $this;
  77.     }
  78.     public function getNormalizedEmail(): string
  79.     {
  80.         return $this->normalizedEmail;
  81.     }
  82.     public function setNormalizedEmail(string $normalizedEmail): self
  83.     {
  84.         $this->normalizedEmail trim($normalizedEmail);
  85.         return $this;
  86.     }
  87.     public function getInstance(): ?Instance
  88.     {
  89.         return $this->instance;
  90.     }
  91.     public function setInstance(Instance $instance): self
  92.     {
  93.         $this->instance $instance;
  94.         return $this;
  95.     }
  96.     public function getSourceOrganizationLabel(): string
  97.     {
  98.         return $this->sourceOrganizationLabel;
  99.     }
  100.     public function setSourceOrganizationLabel(string $sourceOrganizationLabel): self
  101.     {
  102.         $this->sourceOrganizationLabel self::collapseWhitespace($sourceOrganizationLabel);
  103.         return $this;
  104.     }
  105.     public function getCreatedAt(): DateTimeImmutable
  106.     {
  107.         return $this->createdAt;
  108.     }
  109.     public function setCreatedAt(DateTimeImmutable $createdAt): self
  110.     {
  111.         $this->createdAt $createdAt;
  112.         return $this;
  113.     }
  114.     public function getUpdatedAt(): DateTimeImmutable
  115.     {
  116.         return $this->updatedAt;
  117.     }
  118.     public function setUpdatedAt(DateTimeImmutable $updatedAt): self
  119.     {
  120.         $this->updatedAt $updatedAt;
  121.         return $this;
  122.     }
  123.     /**
  124.      * @ORM\PrePersist
  125.      */
  126.     public function onPrePersist(): void
  127.     {
  128.         $now = new DateTimeImmutable();
  129.         $this->createdAt ??= $now;
  130.         $this->updatedAt $this->updatedAt ?? $this->createdAt;
  131.     }
  132.     /**
  133.      * @ORM\PreUpdate
  134.      */
  135.     public function onPreUpdate(): void
  136.     {
  137.         $this->updatedAt = new DateTimeImmutable();
  138.     }
  139.     public function touch(): self
  140.     {
  141.         $this->updatedAt = new DateTimeImmutable();
  142.         return $this;
  143.     }
  144.     private static function collapseWhitespace(string $value): string
  145.     {
  146.         return trim((string) preg_replace('/\s+/u'' 'trim($value)));
  147.     }
  148. }