diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
commit | 4ada86876033fa171e2896d7e3d3c5645d8062db (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/Common | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-reporting-4ada86876033fa171e2896d7e3d3c5645d8062db.tar.xz icingaweb2-module-reporting-4ada86876033fa171e2896d7e3d3c5645d8062db.zip |
Adding upstream version 0.10.0.upstream/0.10.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/Common')
-rw-r--r-- | library/Reporting/Common/Macros.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/library/Reporting/Common/Macros.php b/library/Reporting/Common/Macros.php new file mode 100644 index 0000000..052cdd2 --- /dev/null +++ b/library/Reporting/Common/Macros.php @@ -0,0 +1,49 @@ +<?php + +namespace Icinga\Module\Reporting\Common; + +trait Macros +{ + protected $macros; + + /** + * @param string $name + * + * @return mixed + */ + public function getMacro($name) + { + return $this->macros[$name] ?: null; + } + + /** + * @return mixed + */ + public function getMacros() + { + return $this->macros; + } + + /** + * @param mixed $macros + * + * @return $this + */ + public function setMacros($macros) + { + $this->macros = $macros; + + return $this; + } + + public function resolveMacros($subject) + { + $macros = []; + + foreach ((array) $this->macros as $key => $value) { + $macros['${' . $key . '}'] = $value; + } + + return str_replace(array_keys($macros), array_values($macros), $subject); + } +} |