2015-06-11 08:15:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\CustomVariable;
|
|
|
|
|
2015-06-11 22:44:17 +02:00
|
|
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
2015-06-11 21:33:47 +02:00
|
|
|
|
2015-06-11 08:15:51 +02:00
|
|
|
class CustomVariableArray extends CustomVariable
|
|
|
|
{
|
|
|
|
public function equals(CustomVariable $var)
|
|
|
|
{
|
|
|
|
if (! $var instanceof CustomVariableArray) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:38:06 +02:00
|
|
|
// TODO: better var handlig, fix this
|
|
|
|
return $var->value === $this->value;
|
2015-06-11 08:15:51 +02:00
|
|
|
}
|
2015-06-11 10:39:12 +02:00
|
|
|
|
2015-06-11 21:33:47 +02:00
|
|
|
public function setValue($value)
|
2015-06-11 10:39:12 +02:00
|
|
|
{
|
2015-06-11 21:33:47 +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
|
|
|
}
|
|
|
|
|
2015-06-11 21:33:47 +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]";
|
|
|
|
}
|
2015-06-11 08:15:51 +02:00
|
|
|
}
|