l11n = $l11n; } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { $this->l11n->content = $l11n; $this->l11n->language = $lang; } else { $this->l11n = new BaseStringL11n(); $this->l11n->content = $l11n; $this->l11n->ref = $this->id; $this->l11n->language = $lang; } } /** * Get localization * * @return null|string * * @since 1.0.0 */ public function getL11n() : ?string { return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } /** * Set value * * @param mixed $value Value * @param int $datatype Datatype * * @return void * * @since 1.0.0 */ public function setValue(mixed $value, int $datatype) : void { if ($datatype === AttributeValueType::_STRING) { $this->valueStr = (string) $value; } elseif ($datatype === AttributeValueType::_INT || $datatype === AttributeValueType::_FLOAT_INT || $datatype === AttributeValueType::_BOOL ) { $this->valueInt = (int) $value; } elseif ($datatype === AttributeValueType::_FLOAT) { $this->valueDec = (float) $value; } elseif ($datatype === AttributeValueType::_DATETIME) { $this->valueDat = $value instanceof \DateTime ? $value : new \DateTime((string) $value); } } /** * Get value * * @return null|int|string|float|\DateTimeInterface * * @since 1.0.0 */ public function getValue() : mixed { if ($this->valueStr !== null) { return $this->valueStr; } elseif ($this->valueInt !== null) { return $this->valueInt; } elseif ($this->valueDec !== null) { return $this->valueDec; } elseif ($this->valueDat !== null) { return $this->valueDat; } return null; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'valueInt' => $this->valueInt, 'valueStr' => $this->valueStr, 'valueDec' => $this->valueDec, 'valueDat' => $this->valueDat, 'isDefault' => $this->isDefault, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } }