* [story#74518] add function: setValueByPath.

This commit is contained in:
qixinzhi
2025-05-08 08:16:50 +08:00
committed by 刘刚
parent 1910c41987
commit 2bb12c6298
+34
View File
@@ -337,6 +337,40 @@ class screenModel extends model
return $component;
}
/**
* 通过路径设置值。
* Set value by path.
*
* @param object $option
* @param string $path
* @param string $value
* @access public
* @return void
*/
public function setValueByPath(object &$option, string $path, mixed $value): void
{
$keys = explode('.', $path);
$current = &$option;
foreach ($keys as $key) {
if(is_numeric($key))
{
if(!isset($current[$key])) $current[$key] = array();
}
else
{
if(!isset($current->$key)) $current->$key = new stdclass();
}
if (is_array($current)) {
$current = &$current[$key];
} else {
$current = &$current->$key;
}
}
$current = $value;
}
/**
* Update piovt or chart component chartConfig filters.
*