fieldsResponse = new ArrayCollection(); $this->dateResponse = new \DateTime('now'); $this->publicKey = $this->generateToken(64); } private function generateToken($length = 64){ $hash = ""; while(strlen($hash) < $length){ try { $hash .= hash('sha512', random_bytes($length)); } catch (\Exception $e) { $hash .= hash('sha512', mt_rand(0,$length*10000)); } } return substr($hash, 0,$length); } /** * use to change the pk if its not unique */ public function regeneratePublicKey(){ $this->publicKey = $this->generateToken(); } /** * @return string */ public function getPublicKey(): string { return $this->publicKey; } /** * @return int */ public function getId(): int { return $this->id; } /** * @param FormForgeReasonInterface $reason * @return FormForgeReasonResponseBase */ public function setReason(FormForgeReasonInterface $reason): FormForgeReasonResponseBase { $this->reason = $reason; return $this; } /** * @return FormForgeReasonInterface */ public function getReason(): FormForgeReasonInterface { return $this->reason; } /** * @param FormForgeFieldResponseInterface $fieldResponse * @return FormForgeReasonResponseBase */ public function addFieldResponse(FormForgeFieldResponseInterface $fieldResponse): FormForgeReasonResponseBase { if (!$this->fieldsResponse->contains($fieldResponse)) $this->fieldsResponse->add($fieldResponse); return $this; } /** * @param FormForgeFieldResponseInterface $fieldResponse * @return FormForgeReasonResponseBase */ public function removeFieldResponse(FormForgeFieldResponseInterface $fieldResponse): FormForgeReasonResponseBase { if ($this->fieldsResponse->contains($fieldResponse)) $this->fieldsResponse->remove($fieldResponse); return $this; } /** * @return Collection */ public function getFieldResponse(): Collection { return $this->fieldsResponse; } /** * @param mixed $dateResponse * @return FormForgeReasonResponseBase */ public function setDateResponse(\DateTime $dateResponse) { $this->dateResponse = $dateResponse; return $this; } /** * @return mixed */ public function getDateResponse() { return $this->dateResponse; } /** * @param CustomUserInterface $user * @return FormForgeReasonResponseBase */ public function setUser(CustomUserInterface $user): FormForgeReasonResponseBase { $this->user = $user; return $this; } /** * @return CustomUserInterface|null */ public function getUser(): ?CustomUserInterface { return $this->user; } /** * @param string $locale * @return FormForgeReasonResponseBase */ public function setLocale(string $locale): FormForgeReasonResponseBase { $this->locale = $locale; return $this; } /** * @return string */ public function getLocale(): string { return $this->locale; } public function getValueByTag(string $tag){ foreach ($this->fieldsResponse as $field){ /** * @var $field FormForgeFieldResponse */ if($field->getFormForgeField()->getFieldTag() == $tag) return $field->getValue(); } } /** * @return Directory */ public function getDirectory(): ?Directory { return $this->directory; } /** * @param Directory $directory * @return FormForgeReasonResponseInterface */ public function setDirectory(Directory $directory): FormForgeReasonResponseInterface { $this->directory = $directory; return $this; } }