src/Entity/Contact.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContactRepository;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use geertw\IpAnonymizer\IpAnonymizer;
  10. #[ORM\Entity(repositoryClass: ContactRepository::class)]
  11. class Contact
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id = null;
  17.     #[ORM\Column(length: 255)]
  18.     #[Assert\NotBlank]
  19.     #[Assert\Length(min: "3")]
  20.     private ?string $name = null;
  21.     #[ORM\Column(length: 180)]
  22.     #[Assert\NotBlank]
  23.     #[Assert\Email]
  24.     private ?string $email = null;
  25.     #[ORM\Column(type: Types::TEXT)]
  26.     #[Assert\NotBlank]
  27.     #[Assert\Length(min: "10")]
  28.     private ?string $content = null;
  29.     #[ORM\Column(length: 255)]
  30.     private ?string $ip = '';
  31.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  32.     private ?DateTimeInterface $createdAt;
  33.     public function __construct()
  34.     {
  35.         $this->createdAt = new DateTime();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getName(): ?string
  42.     {
  43.         return $this->name;
  44.     }
  45.     public function setName(string $name): self
  46.     {
  47.         $this->name = $name;
  48.         return $this;
  49.     }
  50.     public function getEmail(): ?string
  51.     {
  52.         return $this->email;
  53.     }
  54.     public function setEmail(string $email): self
  55.     {
  56.         $this->email = $email;
  57.         return $this;
  58.     }
  59.     public function getContent(): ?string
  60.     {
  61.         return $this->content;
  62.     }
  63.     public function setContent(string $content): self
  64.     {
  65.         $this->content = $content;
  66.         return $this;
  67.     }
  68.     public function getIp(): ?string
  69.     {
  70.         return $this->ip;
  71.     }
  72.     public function setIp(string $ip): self
  73.     {
  74.         $this->ip = $ip;
  75.         return $this;
  76.     }
  77.     public function setRawIp(?string $ip): self
  78.     {
  79.         $this->ip = (new IpAnonymizer())->anonymize($ip);
  80.         return $this;
  81.     }
  82.     public function getCreatedAt(): ?DateTimeInterface
  83.     {
  84.         return $this->createdAt;
  85.     }
  86.     public function setCreatedAt(DateTimeInterface $createdAt): self
  87.     {
  88.         $this->createdAt = $createdAt;
  89.         return $this;
  90.     }
  91. }