diff options
Diffstat (limited to 'library/Reporting/Common/Macros.php')
-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); + } +} |