comment = new CommentEmbeddable(); } public function getComment(): CommentEmbeddable { return $this->comment; } public function getFreeText(): ?string { return $this->freeText; } /** * GETTERS. */ public function getId(): ?int { return $this->id; } public function getKind(): ?PersonResourceKind { return $this->kind; } public function getPerson(): ?Person { return $this->person; } /** * @Groups({"read"}) */ public function getResourceKind(): string { if ($this->getPerson() instanceof Person) { return 'person'; } if ($this->getThirdParty() instanceof ThirdParty) { return 'thirdparty'; } if (null !== $this->getFreeText()) { return 'freetext'; } return 'none'; } public function getPersonOwner(): ?Person { return $this->personOwner; } public function getThirdParty(): ?ThirdParty { return $this->thirdParty; } public function setComment(?CommentEmbeddable $comment): self { if (null === $comment) { $this->comment->setComment(''); return $this; } $this->comment = $comment; return $this; } public function setFreeText(?string $freeText): self { $this->freeText = $freeText; if ('' !== $freeText && null !== $freeText) { $this->setPerson(null); $this->setThirdParty(null); } if ('' === $freeText) { $this->freeText = null; } return $this; } public function setKind(?PersonResourceKind $kind): self { $this->kind = $kind; return $this; } public function setPerson(?Person $person): self { $this->person = $person; if (null !== $person) { $this->setFreeText(''); $this->setThirdParty(null); } return $this; } public function setPersonOwner(?Person $personOwner): self { $this->personOwner = $personOwner; return $this; } public function setThirdParty(?ThirdParty $thirdParty): self { $this->thirdParty = $thirdParty; if (null !== $thirdParty) { $this->setFreeText(''); $this->setPerson(null); } return $this; } /** * @Assert\Callback * * @param mixed $payload */ public function validate(ExecutionContextInterface $context, $payload) { if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) { $context->buildViolation('You must associate at least one entity') ->addViolation(); } } }