mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-12 16:34:25 +02:00
Implement Icinga\Util\Enumerate
This commit is contained in:
parent
33d2175b77
commit
982cda6805
62
library/Icinga/Util/Enumerate.php
Normal file
62
library/Icinga/Util/Enumerate.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Util;
|
||||||
|
|
||||||
|
use Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Enumerate
|
||||||
|
*
|
||||||
|
* @see https://docs.python.org/2/library/functions.html#enumerate
|
||||||
|
*
|
||||||
|
* @package Icinga\Util
|
||||||
|
*/
|
||||||
|
class Enumerate implements Iterator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Iterator
|
||||||
|
*/
|
||||||
|
protected $iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Iterator $iterator
|
||||||
|
*/
|
||||||
|
public function __construct(Iterator $iterator)
|
||||||
|
{
|
||||||
|
$this->iterator = $iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rewind()
|
||||||
|
{
|
||||||
|
$this->iterator->rewind();
|
||||||
|
$this->key = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function next()
|
||||||
|
{
|
||||||
|
$this->iterator->next();
|
||||||
|
++$this->key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function valid()
|
||||||
|
{
|
||||||
|
return $this->iterator->valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function current()
|
||||||
|
{
|
||||||
|
return $this->iterator->current();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function key()
|
||||||
|
{
|
||||||
|
return $this->key;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user