values = new ArrayCollection(); $this->required = true; $this->order = 0; $this->publicKey = $this->generateToken(64); $this->deleted = false; } public function setDefault ( FormForgeReasonInterface $_formForgeReason, LinguisticaTradItem $_label , FormForgeType $_type, bool $_required, int $_order, string $_tag, string $_smallClass, string $_mediumClass, string $_largeClass, string $_xLargeClass ){ $this->setFormForgeReason($_formForgeReason); $this->setLabel($_label); $this->setFormForgeType($_type); $this->setRequired($_required); $this->setOrder($_order); $this->setFieldTag($_tag); $this->setSmall($_smallClass); $this->setMedium($_mediumClass); $this->setLarge($_largeClass); $this->setXLarge($_xLargeClass); } /** * @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; } /** * @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; } /** * @param string $fieldTag * @return FormForgeFieldBase */ public function setFieldTag(string $fieldTag): FormForgeFieldBase { $this->fieldTag = $fieldTag; return $this; } /** * @return string */ public function getFieldTag(): string { return $this->fieldTag; } /** * @param FormForgeType $formForgeType * @return FormForgeFieldBase */ public function setFormForgeType(?FormForgeType $formForgeType): self { $this->formForgeType = $formForgeType; return $this; } /** * @return FormForgeType */ public function getFormForgeType(): ?FormForgeType { return $this->formForgeType; } /** * @param string $small * @return FormForgeFieldBase */ public function setSmall(string $small): self { $this->small = $small; return $this; } /** * @return string */ public function getSmall(): string { return $this->small; } /** * @param string $medium * @return FormForgeFieldBase */ public function setMedium(string $medium): self { $this->medium = $medium; return $this; } /** * @return string */ public function getMedium(): string { return $this->medium; } /** * @param string $large * @return FormForgeFieldBase */ public function setLarge(string $large): self { $this->large = $large; return $this; } /** * @return string */ public function getLarge(): string { return $this->large; } /** * @return string */ public function getXLarge(): string { return $this->xLarge; } /** * @param string $xLarge * @return FormForgeFieldBase */ public function setXLarge(string $xLarge): FormForgeFieldBase { $this->xLarge = $xLarge; return $this; } /** * @return string|null */ public function getParameter(): ?string { return $this->parameter; } /** * @param string $parameter|null * @return FormForgeFieldBase */ public function setParameter(?string $parameter): FormForgeFieldBase { $this->parameter = $parameter; return $this; } }