Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Iterator\Repeater Class Reference
Inheritance diagram for Hoa\Iterator\Repeater:

Public Member Functions

 __construct (\Traversable $iterator, $n, $body=null)
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Protected Attributes

 $_iterator = null
 
 $_n = 1
 
 $_i = 1
 
 $_body = null
 

Detailed Description

Class .

Repeat an iterator n-times.

Definition at line 47 of file Repeater.php.

Constructor & Destructor Documentation

Hoa\Iterator\Repeater::__construct ( \Traversable  $iterator,
  $n,
  $body = null 
)

Constructor.

Parameters
\Traversable$iteratorIterator.
int$nRepeat $n-times.
callable$bodyBody.
Returns
void
Exceptions

Definition at line 88 of file Repeater.php.

89  {
90  if (0 >= $n) {
91  throw new Exception(
92  'n must be greater than 0, given %d.',
93  0,
94  $n
95  );
96  }
97 
98  if ($iterator instanceof \IteratorAggregate) {
99  $iterator = $iterator->getIterator();
100  }
101 
102  $this->_iterator = $iterator;
103  $this->_n = $n;
104  $this->_body = $body;
105 
106  return;
107  }

Member Function Documentation

Hoa\Iterator\Repeater::current ( )

Return the current element.

Returns
mixed

Definition at line 114 of file Repeater.php.

115  {
116  return $this->_iterator->current();
117  }
Hoa\Iterator\Repeater::key ( )

Return the key of the current element.

Returns
mixed

Definition at line 124 of file Repeater.php.

125  {
126  return $this->_iterator->key();
127  }
Hoa\Iterator\Repeater::next ( )

Move forward to next element.

Returns
void

Definition at line 134 of file Repeater.php.

135  {
136  return $this->_iterator->next();
137  }
Hoa\Iterator\Repeater::rewind ( )

Rewind the iterator to the first element.

Returns
void

Definition at line 144 of file Repeater.php.

145  {
146  return $this->_iterator->rewind();
147  }

Here is the caller graph for this function:

Hoa\Iterator\Repeater::valid ( )

Check if current position is valid.

Returns
bool

Definition at line 154 of file Repeater.php.

155  {
156  $valid = $this->_iterator->valid();
157 
158  if (true === $valid) {
159  return true;
160  }
161 
162  if (null !== $this->_body) {
163  $handle = &$this->_body;
164  $handle($this->_i);
165  }
166 
167  $this->rewind();
168 
169  if ($this->_n <= $this->_i++) {
170  $this->_i = 1;
171 
172  return false;
173  }
174 
175  return true;
176  }

Here is the call graph for this function:

Member Data Documentation

Hoa\Iterator\Repeater::$_body = null
protected

Definition at line 75 of file Repeater.php.

Hoa\Iterator\Repeater::$_i = 1
protected

Definition at line 68 of file Repeater.php.

Hoa\Iterator\Repeater::$_iterator = null
protected

Definition at line 54 of file Repeater.php.

Hoa\Iterator\Repeater::$_n = 1
protected

Definition at line 61 of file Repeater.php.


The documentation for this class was generated from the following file: