PropertyModifierLConfCustomVar: new modifier

fixes #837
This commit is contained in:
Thomas Gelf 2017-03-09 08:46:18 +01:00
parent e6e51dc2be
commit a7ff250ecd
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
class PropertyModifierLConfCustomVar extends PropertyModifierHook
{
public function transform($value)
{
if ($value === null) {
return null;
}
$vars = (object) array();
$this->extractLConfVars($value, $vars);
return $vars;
}
public function getName()
{
return 'Transform LConf CustomVars to Hash';
}
protected function extractLConfVars($value, $vars)
{
if (is_string($value)) {
$this->extractLConfVar($value, $vars);
} elseif (is_array($value)) {
foreach ($value as $val) {
$this->extractLConfVar($val, $vars);
}
}
}
protected function extractLConfVar($value, $vars)
{
list($key, $val) = preg_split('/ /', $value, 2);
$key = rtrim($key, '_');
$vars->$key = $val;
}
}

View File

@ -38,6 +38,7 @@ $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\Pro
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierMakeBoolean');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierJsonDecode');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierToInt');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierLConfCustomVar');
$this->provideHook('director/Job', $prefix . 'Job\\HousekeepingJob');
$this->provideHook('director/Job', $prefix . 'Job\\ConfigJob');