2015-06-11 22:48:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\IcingaConfig;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
2015-06-23 14:37:23 +02:00
|
|
|
use Icinga\Module\Director\Util;
|
2015-06-11 22:48:41 +02:00
|
|
|
|
|
|
|
class IcingaConfigFile
|
|
|
|
{
|
2015-06-17 19:03:23 +02:00
|
|
|
public static $table = 'director_generated_file';
|
2015-06-18 10:54:44 +02:00
|
|
|
|
2015-06-17 19:03:23 +02:00
|
|
|
public static $keyName = 'checksum';
|
|
|
|
|
2015-06-11 22:48:41 +02:00
|
|
|
protected $content;
|
|
|
|
|
2015-06-18 10:54:44 +02:00
|
|
|
protected $checksum;
|
|
|
|
|
2015-12-15 17:14:36 +01:00
|
|
|
protected $cntObject = 0;
|
|
|
|
|
|
|
|
protected $cntTemplate = 0;
|
|
|
|
|
2015-06-17 10:03:31 +02:00
|
|
|
public function prepend($content)
|
|
|
|
{
|
|
|
|
$this->content = $content . $this->content;
|
2015-06-18 10:54:44 +02:00
|
|
|
$this->checksum = null;
|
2015-06-17 10:03:31 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-11 22:48:41 +02:00
|
|
|
public function getContent()
|
|
|
|
{
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:54:44 +02:00
|
|
|
public function setContent($content)
|
|
|
|
{
|
|
|
|
$this->content = $content;
|
|
|
|
$this->checksum = null;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-12-15 17:14:36 +01:00
|
|
|
public function getObjectCount()
|
|
|
|
{
|
|
|
|
return $this->cntObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTemplateCount()
|
|
|
|
{
|
|
|
|
return $this->cntTemplate;
|
|
|
|
}
|
|
|
|
|
2015-12-16 16:19:58 +01:00
|
|
|
public function getSize()
|
|
|
|
{
|
|
|
|
return strlen($this->content);
|
|
|
|
}
|
|
|
|
|
2015-12-15 17:14:36 +01:00
|
|
|
public function setObjectCount($cnt)
|
|
|
|
{
|
|
|
|
$this->cntObject = $cnt;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTemplateCount($cnt)
|
|
|
|
{
|
|
|
|
$this->cntTemplate = $cnt;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-17 19:03:23 +02:00
|
|
|
public function getHexChecksum()
|
2015-06-11 22:48:41 +02:00
|
|
|
{
|
2015-06-23 14:37:23 +02:00
|
|
|
return Util::binary2hex($this->getChecksum());
|
2015-06-11 22:48:41 +02:00
|
|
|
}
|
|
|
|
|
2015-06-17 19:03:23 +02:00
|
|
|
public function getChecksum()
|
|
|
|
{
|
2015-06-18 10:54:44 +02:00
|
|
|
if ($this->checksum === null) {
|
|
|
|
$this->checksum = sha1($this->content, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->checksum;
|
2015-06-17 19:03:23 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 22:48:41 +02:00
|
|
|
public function addObjects($objects)
|
|
|
|
{
|
|
|
|
foreach ($objects as $object) {
|
|
|
|
$this->addObject($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addObject(IcingaObject $object)
|
|
|
|
{
|
|
|
|
$this->content .= $object->toConfigString();
|
2015-06-18 10:54:44 +02:00
|
|
|
$this->checksum = null;
|
2015-12-15 17:14:36 +01:00
|
|
|
|
|
|
|
if ($object->hasProperty('object_type')) {
|
|
|
|
$type = $object->object_type;
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'object':
|
|
|
|
$this->cntObject++;
|
|
|
|
break;
|
|
|
|
case 'template':
|
|
|
|
$this->cntTemplate++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:54:44 +02:00
|
|
|
return $this;
|
2015-06-11 22:48:41 +02:00
|
|
|
}
|
2015-07-23 15:37:35 +02:00
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->getContent();
|
|
|
|
}
|
2015-06-11 22:48:41 +02:00
|
|
|
}
|