icingaweb2-module-director/library/Director/CustomVariable/CustomVariableArray.php

49 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\Module\Director\CustomVariable;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
class CustomVariableArray extends CustomVariable
{
public function equals(CustomVariable $var)
{
if (! $var instanceof CustomVariableArray) {
return false;
}
return $var->getValue() === $this->getValue();
}
2015-06-11 10:39:12 +02:00
public function setValue($value)
2015-06-11 10:39:12 +02:00
{
$new = array();
foreach ($value as $key => $val) {
$new[$key] = self::wantCustomVariable($key, $val);
}
// WTF?
if ($this->value === $new) {
return $this;
}
$this->value = $new;
$this->setModified();
return $this;
2015-06-11 10:39:12 +02:00
}
public function toConfigString()
{
$str = '[ ' . implode(', ', $this->value) . ' ]';
if (strlen($str) < 60) {
return $str;
}
// Prefix for toConfigString?
return "[\n " . implode(",\n ", $this->value) . "\n]";
}
}