mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 09:14:09 +02:00
Sync: allow to access "deep" values from expressions
This commit is contained in:
parent
d37991627a
commit
b190fd62e3
@ -72,16 +72,14 @@ class Sync
|
|||||||
return $this->getDeepValue($val->$key, $keys);
|
return $this->getDeepValue($val->$key, $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fillVariables($string, $row)
|
protected function getSpecificValue($row, $var)
|
||||||
{
|
{
|
||||||
if (preg_match('/^\${([A-Za-z0-9\._-]+)}$/', $string, $m)) {
|
|
||||||
$var = $m[1];
|
|
||||||
if (strpos($var, '.') === false) {
|
if (strpos($var, '.') === false) {
|
||||||
if (! property_exists($row, $var)) {
|
if (! property_exists($row, $var)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$val = $row->$var;
|
return $row->$var;
|
||||||
} else {
|
} else {
|
||||||
$parts = explode('.', $var);
|
$parts = explode('.', $var);
|
||||||
$main = array_shift($parts);
|
$main = array_shift($parts);
|
||||||
@ -91,13 +89,16 @@ class Sync
|
|||||||
|
|
||||||
return $this->getDeepValue($row->$main, $parts);
|
return $this->getDeepValue($row->$main, $parts);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $val;
|
protected function fillVariables($string, $row)
|
||||||
|
{
|
||||||
|
if (preg_match('/^\${([A-Za-z0-9\._-]+)}$/', $string, $m)) {
|
||||||
|
return $this->getSpecificValue($row, $m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$func = function ($match) use ($row) {
|
$func = function ($match) use ($row) {
|
||||||
// TODO allow to access deep value also here
|
return $this->getSpecificValue($row, $match[1]);
|
||||||
return $row->{$match[1]};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return preg_replace_callback('/\${([A-Za-z0-9\._-]+)}/', $func, $string);
|
return preg_replace_callback('/\${([A-Za-z0-9\._-]+)}/', $func, $string);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user