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

59 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\Module\Director\IcingaConfig;
use Icinga\Data\Db\DbConnection;
use Icinga\Module\Director\Objects\IcingaCommand;
use Icinga\Module\Director\Objects\IcingaHost;
class IcingaConfig
{
protected $files = array();
protected function __construct()
{
}
public function getFiles()
{
return $this->files;
}
public static function fromDb(DbConnection $db)
{
$config = new static;
return $config->loadFromDb($db);
}
protected function loadFromDb(DbConnection $db)
{
$this->db = $db;
$this
->createFileFromDb('zone')
->createFileFromDb('command')
->createFileFromDb('host')
->createFileFromDb('service')
2015-06-12 13:41:38 +02:00
->createFileFromDb('user')
;
2015-06-12 13:38:49 +02:00
return $this;
}
protected function createFileFromDb($type)
{
$class = 'Icinga\\Module\\Director\\Objects\\Icinga' . ucfirst($type);
$objects = $class::loadAll($this->db);
if (! empty($objects)) {
$class = 'Icinga\\Module\\Director\\IcingaConfig\\Icinga'
. ucfirst($type)
. 'sConfigFile';
$file = new $class();
$file->addObjects($objects);
$this->files[$type . 's.conf'] = $file;
}
return $this;
}
}