type = $type; $this->setValue($value); if (!empty($name)) { $this->setL11n($name); } } /** * Get id * * @return int * * @since 1.0.0 */ public function getId() : int { return $this->id; } /** * Set l11n * * @param string|ItemAttributeTypeL11n $l11n Tag article l11n * @param string $lang Language * * @return void * * @since 1.0.0 */ public function setL11n(string | ItemAttributeValueL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { if ($l11n instanceof ItemAttributeValueL11n) { $this->l11n = $l11n; } elseif (isset($this->l11n) && $this->l11n instanceof ItemAttributeValueL11n) { $this->l11n->title = $l11n; } else { $this->l11n = new ItemAttributeValueL11n(); $this->l11n->title = $l11n; $this->l11n->setLanguage($lang); } } /** * @return string * * @since 1.0.0 */ public function getL11n() : string { return $this->l11n instanceof ItemAttributeTypeL11n ? $this->l11n->title : $this->l11n; } /** * Set value * * @param int|string|float|\DateTimeInterface $value Value * * @return void * * @since 1.0.0 */ public function setValue(mixed $value) : void { if (\is_string($value)) { $this->valueStr = $value; } elseif (\is_int($value)) { $this->valueInt = $value; } elseif (\is_float($value)) { $this->valueDec = $value; } elseif ($value instanceof \DateTimeInterface) { $this->valueDat = $value; } } /** * Get value * * @return null|int|string|float|\DateTimeInterface * * @since 1.0.0 */ public function getValue() : mixed { if (!empty($this->valueStr)) { return $this->valueStr; } elseif (!empty($this->valueInt)) { return $this->valueInt; } elseif (!empty($this->valueDec)) { return $this->valueDec; } elseif ($this->valueDat instanceof \DateTimeInterface) { return $this->valueDat; } return null; } /** * Set language * * @param string $language Language * * @return void * * @since 1.0.0 */ public function setLanguage(string $language) : void { $this->language = $language; } /** * Get language * * @return string * * @since 1.0.0 */ public function getLanguage() : string { return $this->language; } /** * Set country * * @param string $country Country * * @return void * * @since 1.0.0 */ public function setCountry(string $country) : void { $this->country = $country; } /** * Get country * * @return string * * @since 1.0.0 */ public function getCountry() : string { return $this->country; } /** * {@inheritdoc} */ public function toArray() : array { return [ 'id' => $this->id, 'type' => $this->type, 'valueInt' => $this->valueInt, 'valueStr' => $this->valueStr, 'valueDec' => $this->valueDec, 'valueDat' => $this->valueDat, 'isDefault' => $this->isDefault, 'language' => $this->language, 'country' => $this->country, ]; } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } }