diff --git a/library/Director/IcingaConfig/ExtensibleSet.php b/library/Director/IcingaConfig/ExtensibleSet.php index 3c8f7fc4..1addfee3 100644 --- a/library/Director/IcingaConfig/ExtensibleSet.php +++ b/library/Director/IcingaConfig/ExtensibleSet.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\IcingaConfig; use Icinga\Exception\InvalidPropertyException; +use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; class ExtensibleSet { @@ -89,6 +90,38 @@ class ExtensibleSet return $this; } + public function renderAs($key, $prefix = ' ') + { + $parts = array(); + + if ($this->ownValues !== null) { + $parts[] = c::renderKeyValue( + $key, + c::renderArray($this->ownValues), + $prefix + ); + } + + if (! empty($this->plusValues)) { + $parts[] = c::renderKeyOperatorValue( + $key, + '+=', + c::renderArray($this->plusValues), + $prefix + ); + } + if (! empty($this->minusValues)) { + $parts[] = c::renderKeyOperatorValue( + $key, + '-=', + c::renderArray($this->plusValues), + $prefix + ); + } + + return implode('', $parts); + } + protected function hasBeenResolved() { return $this->resolvedValues !== null; diff --git a/test/php/library/Director/IcingaConfig/ExtensibleSetTest.php b/test/php/library/Director/IcingaConfig/ExtensibleSetTest.php index f1fa189b..23fbad73 100644 --- a/test/php/library/Director/IcingaConfig/ExtensibleSetTest.php +++ b/test/php/library/Director/IcingaConfig/ExtensibleSetTest.php @@ -132,4 +132,20 @@ class ExtensibleSetTest extends BaseTestCase $child->getResolvedValues() ); } + + public function testCombinedDefinitionRendersCorrectly() + { + $set = new ExtensibleSet(array('pre', 'def', 'ined')); + $set->blacklist('and', 'not', 'those'); + $set->extend('plus this'); + + $out = ' key_name = [ "pre", "def", "ined" ]' . "\n" + . ' key_name += [ "plus this" ]' . "\n" + . ' key_name -= [ "plus this" ]' . "\n"; + + $this->assertEquals( + $out, + $set->renderAs('key_name') + ); + } }