* zin: add methods to append string to property.

This commit is contained in:
sunhao
2024-02-20 09:23:42 +08:00
parent f88f71c3bc
commit d2ed1bc055
+31
View File
@@ -283,6 +283,37 @@ class dataset
return $this->get($prop, array());
}
/**
* Get string value, if not value exists, return an empty string.
*
* @access public
* @param string $prop Property name.
* @return string
*/
public function getStr(string $prop): string
{
$val = $this->get($prop);
if(is_null($val)) return '';
return (string)$val;
}
/**
* Append string to property.
*
* @access public
* @param string $prop Property name.
* @param string $str String to append.
* @param string $joiner Joiner string.
* @return dataset
*/
public function appendToStr(string $prop, string $str, string $joiner = ''): dataset
{
$val = $this->getStr($prop);
if(strlen($val) > 0) $val .= $joiner . $str;
else $val = $str;
return $this->set($prop, $val);
}
/**
* Delete property by name.
*