icingaweb2-module-director/library/Director/IcingaConfig/IcingaConfigFile.php

72 lines
1.4 KiB
PHP
Raw Normal View History

<?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;
class IcingaConfigFile
{
public static $table = 'director_generated_file';
public static $keyName = 'checksum';
protected $content;
protected $checksum;
public function prepend($content)
{
$this->content = $content . $this->content;
$this->checksum = null;
return $this;
}
public function getContent()
{
return $this->content;
}
public function setContent($content)
{
$this->content = $content;
$this->checksum = null;
return $this;
}
public function getHexChecksum()
{
2015-06-23 14:37:23 +02:00
return Util::binary2hex($this->getChecksum());
}
public function getChecksum()
{
if ($this->checksum === null) {
$this->checksum = sha1($this->content, true);
}
return $this->checksum;
}
public function addObjects($objects)
{
foreach ($objects as $object) {
$this->addObject($object);
}
return $this;
}
public function addObject(IcingaObject $object)
{
$this->content .= $object->toConfigString();
$this->checksum = null;
return $this;
}
2015-07-23 15:37:35 +02:00
public function __toString()
{
return $this->getContent();
}
}