strValues = array(); $this->publicKey = $this->generateToken(64); $this->deleted = false; } /** * @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(); } /** * @return int */ public function getId(): int { return $this->id; } /** * @param FormForgeFieldInterface $formForgeField * @return FormForgeFieldValueBase */ public function setFormForgeField(FormForgeFieldInterface $formForgeField): FormForgeFieldValueBase { $this->formForgeField = $formForgeField; return $this; } /** * @return FormForgeFieldInterface */ public function getFormForgeField(): FormForgeFieldInterface { return $this->formForgeField; } /** * @param int $order * @return FormForgeFieldValueBase */ public function setOrder(int $order): FormForgeFieldValueBase { $this->order = $order; return $this; } /** * @return int */ public function getOrder(): int { return $this->order; } /** * @param string $strValue * @param string $locale * @return $this|LinguisticaTradItem */ public function addStrValues($strValue, $locale) { $this->strValues[$locale] = $strValue; return $this; } /** * @return array */ public function getStrValues(): array { return $this->strValues; } /** * @return string */ public function getPublicKey(): string { return $this->publicKey; } /** * @param bool $deleted * @return FormForgeFieldValueBase */ public function setDeleted(bool $deleted): FormForgeFieldValueBase { $this->deleted = $deleted; return $this; } /** * @return bool */ public function isDeleted(): bool { return $this->deleted; } public function setStrValues($strValues): self { $this->strValues = $strValues; return $this; } // public function setPublicKey(string $publicKey): self // { // $this->publicKey = $publicKey; // // return $this; // } public function show($locale) { if(isset($this->strValues[$locale]) && $this->strValues[$locale] !='') return $this->strValues[$locale]; else if(isset($this->strValues['en']) && $this->strValues['en'] !='') return $this->strValues['en']; else { foreach ($this->strValues as $lang => $text) if($text != '') return $text; } return ''; } public function setPublicKey(string $publicKey): self { $this->publicKey = $publicKey; return $this; } }