buildCheck(); /** * null or empty string is considered not found */ if ($this->value === null || trim($this->value) === "") { throw new ExceptionNotFound("The value was not found for the metadata ($this)"); } return $this->value; } public function valueIsNotNull(): bool { return $this->value !== null; } /** * @param null|string $value * @return $this * @throws ExceptionBadArgument */ public function setValue($value): Metadata { if ($value !== null && !is_string($value)) { throw new ExceptionBadArgument("The value of the metadata ($this) is not a string", $this->getCanonical()); } $value = trim($value); if ($value === "") { /** * TODO: move this into the function {@link MetadataText::setFromStoreValueWithoutException()} ?? * form don't return null only empty string * equivalent to null */ return $this; } $possibleValues = $this->getPossibleValues(); if ($possibleValues !== null) { if (!in_array($value, $possibleValues)) { throw new ExceptionBadArgument("The value ($value) for the metadata ({$this->getName()}) is not one of the possible following values: " . implode(", ", $possibleValues) . "."); } } $this->value = $value; return $this; } /** * @throws ExceptionCompile */ public function setFromStoreValue($value): Metadata { return $this->setValue($value); } public function setFromStoreValueWithoutException($value): Metadata { if (empty($value)) { $this->value = null; return $this; } if (!is_string($value)) { LogUtility::msg("This value of a text metadata is not a string. " . var_export($value, true)); return $this; } $this->value = $value; return $this; } public function getDefaultValue() { return null; } }