icingaweb2/modules/setup/library/Setup/RequirementsRenderer.php
Eric Lippmann 662de28f85 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-26 17:49:26 +01:00

69 lines
2.1 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// 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[] = '<ul class="requirements">';
}
public function endIteration(): void
{
$this->tags[] = '</ul>';
}
public function beginChildren(): void
{
$this->tags[] = '<li>';
/** @var RequirementSet $currentSet */
$currentSet = $this->getSubIterator();
$state = $currentSet->getState() ? 'fulfilled' : ($currentSet->isOptional() ? 'not-available' : 'missing');
$this->tags[] = '<ul class="set-state ' . $state . '">';
}
public function endChildren(): void
{
$this->tags[] = '</ul>';
$this->tags[] = '</li>';
}
public function render()
{
foreach ($this as $requirement) {
$this->tags[] = '<li class="clearfix">';
$this->tags[] = '<div class="title"><h2>' . $requirement->getTitle() . '</h2></div>';
$this->tags[] = '<div class="description">';
$descriptions = $requirement->getDescriptions();
if (count($descriptions) > 1) {
$this->tags[] = '<ul>';
foreach ($descriptions as $d) {
$this->tags[] = '<li>' . $d . '</li>';
}
$this->tags[] = '</ul>';
} elseif (! empty($descriptions)) {
$this->tags[] = $descriptions[0];
}
$this->tags[] = '</div>';
$this->tags[] = '<div class="state ' . ($requirement->getState() ? 'fulfilled' : (
$requirement->isOptional() ? 'not-available' : 'missing'
)) . '">' . $requirement->getStateText() . '</div>';
$this->tags[] = '</li>';
}
return implode("\n", $this->tags);
}
public function __toString()
{
return $this->render();
}
}