icingaweb2/library/Icinga/File/Ini/Dom/Document.php
Matthias Jentsch f8e2dc850c Drop IniEditor and clean up IniWriter
Replace the ini editor code with a new parser implementation that manipulates a DOM. Do not support capabillities that are no longer needed, like nested configurations, section inheritance, section-less properties.
2015-08-05 18:10:17 +02:00

81 lines
1.5 KiB
PHP

<?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)
{
return isset($this->sections[$name]);
}
/**
* @param string $name
*
* @return Section
*/
public function getSection($name)
{
return $this->sections[$name];
}
/**
* @param string $name
* @param Section $section
*
* @return Section
*/
public function setSection($name, Section $section)
{
return $this->sections[$name] = $section;
}
/**
* @param string $name
*/
public function removeSection($name)
{
unset ($this->sections[$name]);
}
/**
* @return string
*/
public function render()
{
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;
}
}