Sync: allow to access "deep" values from expressions

This commit is contained in:
Thomas Gelf 2015-12-02 15:59:31 +01:00
parent d37991627a
commit b190fd62e3

View File

@ -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);