From 522e6f35db1d3d9f0c5debcfb7ced9f05a959bb7 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 6 Apr 2020 15:51:19 +0200 Subject: [PATCH] CompatObject: Add support for value transformation --- library/Icingadb/Compat/CompatObject.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/library/Icingadb/Compat/CompatObject.php b/library/Icingadb/Compat/CompatObject.php index d6a6b751..dca7c121 100644 --- a/library/Icingadb/Compat/CompatObject.php +++ b/library/Icingadb/Compat/CompatObject.php @@ -145,18 +145,29 @@ trait CompatObject } if (isset($this->legacyColumns[$name])) { - $name = $this->legacyColumns[$name]; + $opts = $this->legacyColumns[$name]; + if ($opts === null) { + return null; + } - if (is_array($name)) { + $path = $opts['path']; + $value = null; + + if (! empty($path)) { $value = $this->object; do { - $col = array_shift($name); + $col = array_shift($path); $value = $value->$col; - } while (! empty($name)); - - return $value; + } while (! empty($path)); } + + if (isset($opts['type'])) { + $method = 'get' . ucfirst($opts['type']) . 'Type'; + $value = $this->$method($value); + } + + return $value; } return $this->object->$name;