mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-22 21:34:28 +02:00
Requirements: Do not implement ArrayIterator but RecursiveIterator
refs #8508
This commit is contained in:
parent
551207b5b8
commit
d0a8dd8973
@ -1,13 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use \RecursiveIteratorIterator;
|
||||||
use Icinga\Web\Wizard;
|
use Icinga\Web\Wizard;
|
||||||
|
|
||||||
$requirements = $form->getRequirements();
|
$requirements = $form->getRequirements();
|
||||||
|
$iterator = new RecursiveIteratorIterator($requirements);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<table class="requirements">
|
<table class="requirements">
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($requirements as $requirement): ?>
|
<?php foreach ($iterator as $requirement): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><h2><?= $requirement->getTitle(); ?></h2></td>
|
<td><h2><?= $requirement->getTitle(); ?></h2></td>
|
||||||
<td style="width: 50%">
|
<td style="width: 50%">
|
||||||
|
@ -3,14 +3,13 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Setup;
|
namespace Icinga\Module\Setup;
|
||||||
|
|
||||||
use ArrayIterator;
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use IteratorAggregate;
|
use RecursiveIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container to store and handle requirements
|
* Container to store and handle requirements
|
||||||
*/
|
*/
|
||||||
class Requirements implements IteratorAggregate
|
class Requirements implements RecursiveIterator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Mode AND (all requirements must met)
|
* Mode AND (all requirements must met)
|
||||||
@ -94,7 +93,7 @@ class Requirements implements IteratorAggregate
|
|||||||
public function add(Requirement $requirement)
|
public function add(Requirement $requirement)
|
||||||
{
|
{
|
||||||
$merged = false;
|
$merged = false;
|
||||||
foreach ($this as $knownRequirement) {
|
foreach ($this->requirements as $knownRequirement) {
|
||||||
if ($knownRequirement instanceof Requirement && $requirement->equals($knownRequirement)) {
|
if ($knownRequirement instanceof Requirement && $requirement->equals($knownRequirement)) {
|
||||||
if ($this->getMode() === static::MODE_AND && !$requirement->isOptional()) {
|
if ($this->getMode() === static::MODE_AND && !$requirement->isOptional()) {
|
||||||
$knownRequirement->setOptional(false);
|
$knownRequirement->setOptional(false);
|
||||||
@ -142,16 +141,6 @@ class Requirements implements IteratorAggregate
|
|||||||
return $this->containsMandatoryRequirements || $this->getMode() === static::MODE_OR;
|
return $this->containsMandatoryRequirements || $this->getMode() === static::MODE_OR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an iterator of all registered requirements
|
|
||||||
*
|
|
||||||
* @return ArrayIterator
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new ArrayIterator($this->getAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the given requirements
|
* Register the given requirements
|
||||||
*
|
*
|
||||||
@ -162,7 +151,7 @@ class Requirements implements IteratorAggregate
|
|||||||
public function merge(Requirements $requirements)
|
public function merge(Requirements $requirements)
|
||||||
{
|
{
|
||||||
if ($this->getMode() === static::MODE_OR && $requirements->getMode() === static::MODE_OR) {
|
if ($this->getMode() === static::MODE_OR && $requirements->getMode() === static::MODE_OR) {
|
||||||
foreach ($requirements as $requirement) {
|
foreach ($requirements->getAll() as $requirement) {
|
||||||
if ($requirement instanceof static) {
|
if ($requirement instanceof static) {
|
||||||
$this->merge($requirement);
|
$this->merge($requirement);
|
||||||
} else {
|
} else {
|
||||||
@ -188,7 +177,7 @@ class Requirements implements IteratorAggregate
|
|||||||
public function fulfilled()
|
public function fulfilled()
|
||||||
{
|
{
|
||||||
$state = false;
|
$state = false;
|
||||||
foreach ($this as $requirement) {
|
foreach ($this->requirements as $requirement) {
|
||||||
if ($requirement instanceof static) {
|
if ($requirement instanceof static) {
|
||||||
if ($requirement->fulfilled()) {
|
if ($requirement->fulfilled()) {
|
||||||
if ($this->getMode() === static::MODE_OR) {
|
if ($this->getMode() === static::MODE_OR) {
|
||||||
@ -218,4 +207,71 @@ class Requirements implements IteratorAggregate
|
|||||||
|
|
||||||
return $state;
|
return $state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the current element represents a nested set of requirements
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasChildren()
|
||||||
|
{
|
||||||
|
$current = $this->current();
|
||||||
|
return $current instanceof static;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a iterator for the current nested set of requirements
|
||||||
|
*
|
||||||
|
* @return RecursiveIterator
|
||||||
|
*/
|
||||||
|
public function getChildren()
|
||||||
|
{
|
||||||
|
return $this->current();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewind the iterator to its first element
|
||||||
|
*/
|
||||||
|
public function rewind()
|
||||||
|
{
|
||||||
|
reset($this->requirements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the current iterator position is valid
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function valid()
|
||||||
|
{
|
||||||
|
return $this->key() !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current element in the iteration
|
||||||
|
*
|
||||||
|
* @return Requirement|Requirements
|
||||||
|
*/
|
||||||
|
public function current()
|
||||||
|
{
|
||||||
|
return current($this->requirements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the position of the current element in the iteration
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function key()
|
||||||
|
{
|
||||||
|
return key($this->requirements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Advance the iterator to the next element
|
||||||
|
*/
|
||||||
|
public function next()
|
||||||
|
{
|
||||||
|
next($this->requirements);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user