// SPDX-License-Identifier: GPL-3.0-or-later
namespace Icinga\Module\Setup;
use RecursiveIteratorIterator;
class RequirementsRenderer extends RecursiveIteratorIterator
{
protected $tags;
public function beginIteration(): void
{
$this->tags[] = '
';
}
public function endIteration(): void
{
$this->tags[] = '
';
}
public function beginChildren(): void
{
$this->tags[] = '';
/** @var RequirementSet $currentSet */
$currentSet = $this->getSubIterator();
$state = $currentSet->getState() ? 'fulfilled' : ($currentSet->isOptional() ? 'not-available' : 'missing');
$this->tags[] = '';
}
public function endChildren(): void
{
$this->tags[] = '
';
$this->tags[] = '';
}
public function render()
{
foreach ($this as $requirement) {
$this->tags[] = '';
$this->tags[] = '' . $requirement->getTitle() . '
';
$this->tags[] = '';
$descriptions = $requirement->getDescriptions();
if (count($descriptions) > 1) {
$this->tags[] = '
';
foreach ($descriptions as $d) {
$this->tags[] = '- ' . $d . '
';
}
$this->tags[] = '
';
} elseif (! empty($descriptions)) {
$this->tags[] = $descriptions[0];
}
$this->tags[] = '
';
$this->tags[] = '' . $requirement->getStateText() . '
';
$this->tags[] = '';
}
return implode("\n", $this->tags);
}
public function __toString()
{
return $this->render();
}
}