Implement Icinga\Util\Enumerate

This commit is contained in:
Alexander Klimov 2014-09-05 12:01:14 +02:00
parent 33d2175b77
commit 982cda6805
1 changed files with 62 additions and 0 deletions

View 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;
}
}