<?phpnamespace App\Entity;use App\Repository\ContactPropertyValueRepository;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Context\ExecutionContextInterface;use Symfony\Component\Validator\Constraints as Assert;/** * @ORM\Entity(repositoryClass=ContactPropertyValueRepository::class) */class ContactPropertyValue{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\ManyToOne(targetEntity=Contact::class, inversedBy="contactPropertyValues") * @ORM\JoinColumn(nullable=false) */ private $contact; /** * @ORM\ManyToOne(targetEntity=Property::class, inversedBy="contactPropertyValues") * @ORM\JoinColumn(nullable=false) */ private $property; /** * @ORM\Column(type="string", length=255, nullable=true) */ private $value; /** * @Assert\Callback */ public function validate(ExecutionContextInterface $context, $playload){ if($this->value == null) return; if($this->property->getValidationClass() == null) return; $class = $this->property->getValidationClass(); $validator = new $class(); $isValidate = $validator->validate($this->value); if(!$isValidate){ $context->buildViolation($validator->getErrorMessage()) ->atPath('value') ->addViolation(); } } public function getId(): ?int { return $this->id; } public function getContact(): ?Contact { return $this->contact; } public function setContact(?Contact $contact): self { $this->contact = $contact; return $this; } public function getProperty(): ?Property { return $this->property; } public function setProperty(?Property $property): self { $this->property = $property; return $this; } public function getValue() { return $this->value; } public function setValue($value): self { if (is_a($value, 'DateTime')) { $this->value = $value->format('d/m/Y'); }elseif(is_array($value)){ $this->value = "[".implode(",",$value)."]"; }else{ $this->value = $value; } return $this; }}