values = new ArrayCollection(); $this->type = FormForgeFieldType::TEXT; $this->required = true; $this->order = 0; $this->publicKey = $this->generateToken(64); $this->deleted = false; } public function setDefault(FormForgeReasonInterface $formForgeReason,LinguisticaTradItem $label , $type, $required, $order){ $this->setFormForgeReason($formForgeReason); $this->setLabel($label); $this->setType($type); $this->setRequired($required); $this->setOrder($order); } /** * @param int $length * @return bool|string */ 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(); } /** * Get id * * @return int */ public function getId() { return $this->id; } /** * @param FormForgeReasonInterface $formForgeReason * @return FormForgeFieldBase */ public function setFormForgeReason(FormForgeReasonInterface $formForgeReason): FormForgeFieldBase { $this->formForgeReason = $formForgeReason; return $this; } /** * @return FormForgeReasonInterface */ public function getFormForgeReason(): FormForgeReasonInterface { return $this->formForgeReason; } /** * @param LinguisticaTradItem $label * @return FormForgeFieldBase */ public function setLabel(LinguisticaTradItem $label): FormForgeFieldBase { $this->label = $label; return $this; } /** * @return LinguisticaTradItem */ public function getLabel(): LinguisticaTradItem { return $this->label; } /** * @param FormForgeFieldValueInterface $value * @return FormForgeFieldBase */ public function addValue(FormForgeFieldValueInterface $value): FormForgeFieldBase { if(!$this->values->contains($value)) $this->values->add($value); return $this; } /** * @param FormForgeFieldValueInterface $value * @return FormForgeFieldBase */ public function removeValue(FormForgeFieldValueInterface $value): FormForgeFieldBase { if($this->values->contains($value)) $this->values->remove($value); return $this; } /** * @return Collection */ public function getValues(): Collection { return $this->values; } /** * Set type * * @param integer $type * * @return $this */ public function setType($type) { $this->type = $type; return $this; } /** * Get type * * @return int */ public function getType() { return $this->type; } /** * @param int $order * @return FormForgeFieldBase */ public function setOrder(int $order): FormForgeFieldBase { $this->order = $order; return $this; } /** * @return int */ public function getOrder(): int { return $this->order; } /** * @return string */ public function getPublicKey(): string { return $this->publicKey; } /** * @param bool $deleted * @return FormForgeFieldBase */ public function setDeleted(bool $deleted): FormForgeFieldBase { $this->deleted = $deleted; return $this; } /** * @return bool */ public function isDeleted(): bool { return $this->deleted; } /** * @param $required * @return $this */ public function setRequired($required) { $this->required = $required; return $this; } /** * @return bool */ public function getRequired() { return $this->required; } public function setPublicKey(string $publicKey): self { $this->publicKey = $publicKey; return $this; } }