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

Public Member Functions

 __construct (Praspel\Model\Declaration $declaration, $keyType=self::KEY_AS_VARIABLE_NAME)
 
 extract ()
 
 current ()
 
 key ()
 
 next ()
 
 rewind ()
 
 valid ()
 

Public Attributes

const KEY_AS_VARIABLE_NAME = 0
 
const KEY_AS_VARIABLE_POSITION = 1
 

Protected Member Functions

 _current ()
 

Protected Attributes

 $_declaration = null
 
 $_keyType = null
 
 $_variables = []
 
 $_key = -1
 
 $_current = null
 
 $_coverage = null
 

Detailed Description

Class .

An easy way to iterate over data described by Praspel.

Definition at line 50 of file Sampler.php.

Constructor & Destructor Documentation

Hoa\Praspel\Iterator\Sampler::__construct ( Praspel\Model\Declaration  $declaration,
  $keyType = self::KEY_AS_VARIABLE_NAME 
)

Construct.

Parameters
\Hoa\Praspel\Model\Declaration$declarationDeclaration.
int$keyTypeKey type (plese, see self::KEY_AS* constants).
Returns
void

Definition at line 120 of file Sampler.php.

123  {
124  $this->_declaration = $declaration;
125  $this->_keyType = $keyType;
126 
127  return;
128  }

Member Function Documentation

Hoa\Praspel\Iterator\Sampler::_current ( )
protected

Prepare the current value.

Returns
void

Definition at line 186 of file Sampler.php.

187  {
188  $current = $this->_coverage->current();
189  $handle = [];
190 
191  if (self::KEY_AS_VARIABLE_NAME === $this->_keyType) {
192  foreach ($current as $name => $domain) {
193  $handle[$name] = $domain->sample();
194  }
195  } else {
196  foreach ($current as $domain) {
197  $handle[] = $domain->sample();
198  }
199  }
200 
201  ++$this->_key;
202  $this->_current = $handle;
203 
204  return;
205  }

Here is the caller graph for this function:

Hoa\Praspel\Iterator\Sampler::current ( )

Get current value.

Returns
array

Definition at line 153 of file Sampler.php.

154  {
155  return $this->_current;
156  }

Here is the caller graph for this function:

Hoa\Praspel\Iterator\Sampler::extract ( )

Consider some variables. Example: $this->extract('x', 'y', 'z')

Parameters
string$variableVariable name.
...... ...
Returns

Definition at line 139 of file Sampler.php.

140  {
141  foreach (func_get_args() as $variable) {
142  $this->_variables[] = $this->_declaration[$variable];
143  }
144 
145  return $this;
146  }
Hoa\Praspel\Iterator\Sampler::key ( )

Get current key.

Returns
int

Definition at line 163 of file Sampler.php.

164  {
165  return $this->_key;
166  }
Hoa\Praspel\Iterator\Sampler::next ( )

Compute the next value and return it.

Returns
array

Definition at line 173 of file Sampler.php.

174  {
175  $this->_coverage->next();
176  $this->_current();
177 
178  return $this->current();
179  }

Here is the call graph for this function:

Hoa\Praspel\Iterator\Sampler::rewind ( )

Rewind the iterator.

Returns
void

Definition at line 212 of file Sampler.php.

213  {
214  $this->_key = -1;
215  $this->_current = null;
216 
217  if (null === $this->_coverage) {
218  if (empty($this->_variables)) {
219  $this->_variables = $this->_declaration->getLocalVariables();
220  }
221 
222  $this->_coverage = new Coverage\Domain($this->_variables);
223  }
224 
225  $this->_coverage->rewind();
226  $this->_current();
227 
228  return;
229  }

Here is the call graph for this function:

Hoa\Praspel\Iterator\Sampler::valid ( )

Check if there is enough data to continue.

Returns
bool

Definition at line 236 of file Sampler.php.

237  {
238  return $this->_coverage->valid();
239  }

Member Data Documentation

Hoa\Praspel\Iterator\Sampler::$_coverage = null
protected

Definition at line 106 of file Sampler.php.

Hoa\Praspel\Iterator\Sampler::$_current = null
protected

Definition at line 99 of file Sampler.php.

Hoa\Praspel\Iterator\Sampler::$_declaration = null
protected

Definition at line 71 of file Sampler.php.

Hoa\Praspel\Iterator\Sampler::$_key = -1
protected

Definition at line 92 of file Sampler.php.

Hoa\Praspel\Iterator\Sampler::$_keyType = null
protected

Definition at line 78 of file Sampler.php.

Hoa\Praspel\Iterator\Sampler::$_variables = []
protected

Definition at line 85 of file Sampler.php.

const Hoa\Praspel\Iterator\Sampler::KEY_AS_VARIABLE_NAME = 0

Key value is variable name.

int

Definition at line 57 of file Sampler.php.

const Hoa\Praspel\Iterator\Sampler::KEY_AS_VARIABLE_POSITION = 1

Key value is variable position.

int

Definition at line 64 of file Sampler.php.


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