2015-08-05 14:21:46 +02:00
|
|
|
<?php
|
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
|
|
|
|
|
|
namespace Icinga\File\Ini\Dom;
|
|
|
|
|
|
|
|
class Document
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $sections = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $commentsDangling;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Section $section
|
|
|
|
*/
|
|
|
|
public function addSection(Section $section)
|
|
|
|
{
|
|
|
|
$this->sections[$section->getName()] = $section;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasSection($name)
|
|
|
|
{
|
2015-08-07 09:26:50 +02:00
|
|
|
return isset($this->sections[trim($name)]);
|
2015-08-05 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return Section
|
|
|
|
*/
|
|
|
|
public function getSection($name)
|
|
|
|
{
|
2015-08-07 09:26:50 +02:00
|
|
|
return $this->sections[trim($name)];
|
2015-08-05 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param Section $section
|
|
|
|
*
|
|
|
|
* @return Section
|
|
|
|
*/
|
|
|
|
public function setSection($name, Section $section)
|
|
|
|
{
|
2015-08-07 09:26:50 +02:00
|
|
|
return $this->sections[trim($name)] = $section;
|
2015-08-05 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function removeSection($name)
|
|
|
|
{
|
2015-08-07 09:26:50 +02:00
|
|
|
unset ($this->sections[trim($name)]);
|
2015-08-05 14:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
2015-08-06 17:21:52 +02:00
|
|
|
$sections = array();
|
2015-08-05 14:21:46 +02:00
|
|
|
foreach ($this->sections as $section) {
|
|
|
|
$sections []= $section->render();
|
|
|
|
}
|
|
|
|
$str = implode(PHP_EOL, $sections);
|
|
|
|
if (! empty($this->commentsDangling)) {
|
|
|
|
foreach ($this->commentsDangling as $comment) {
|
|
|
|
$str .= PHP_EOL . $comment->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
}
|