2015-06-11 22:48:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\IcingaConfig;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
|
|
|
|
|
|
|
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-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-06-17 19:03:23 +02:00
|
|
|
public function getHexChecksum()
|
2015-06-11 22:48:41 +02:00
|
|
|
{
|
2015-06-18 10:54:44 +02:00
|
|
|
return current(unpack('H*', $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;
|
|
|
|
return $this;
|
2015-06-11 22:48:41 +02:00
|
|
|
}
|
|
|
|
}
|