src/Entity/Contact.php line 15
<?php
namespace App\Entity;
use App\Entity\Traits\TimestampableTrait;
use App\Repository\ContactRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Validator as AppAssert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Entity(repositoryClass: ContactRepository::class)]
#[AppAssert\CheckExistedParticipation()]
class Contact
{
use TimestampableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 10, nullable: true)]
#[Assert\NotBlank(message: "La civilité est obligatoire")]
private ?string $civility = null;
#[ORM\Column(length: 80)]
#[Assert\NotBlank(message: "Le nom est obligatoire")]
#[Assert\Regex(pattern: "/^[\p{L}\-\s]+$/u", message: 'Ce champ est invalide')]
private string $lastname;
#[ORM\Column(length: 80)]
#[Assert\NotBlank(message: "Le prénom est obligatoire")]
#[Assert\Regex(pattern: "/^[\p{L}\-\s]+$/u", message: 'Ce champ est invalide')]
private string $firstname;
#[ORM\Column(length: 50)]
#[Assert\NotBlank(message: "Le mail est obligatoire")]
private string $email;
#[ORM\Column(length: 255, nullable: true)]
private ?string $reference = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: "Le sujet est obligatoire")]
private string $title;
#[ORM\Column(type: Types::TEXT)]
#[Assert\NotBlank(message: "Le message est obligatoire")]
private string $message;
public function getId(): ?int
{
return $this->id;
}
public function getCivility(): ?string
{
return $this->civility;
}
public function setCivility(?string $civility): self
{
$this->civility = $civility;
return $this;
}
public function getLastname(): string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFirstname(): string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getMessage(): string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function __toArray()
{
return call_user_func('get_object_vars', $this);
}
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (array_key_exists('email', $this->__toArray()) && !filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
$context->buildViolation("Le format de l'e-mail ou les caractères insérés ne sont pas valides.")
->atPath('email')
->addViolation();
}
}
}