Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Generator Class Reference
Inheritance diagram for Generator:
AbstractSource

Public Member Functions

 __construct (array $rowPattern, $limit)
 
 valid ()
 
- Public Member Functions inherited from AbstractSource
 __construct (array $colNames)
 
 getColNames ()
 
 current ()
 
 next ()
 
 key ()
 
 valid ()
 
 rewind ()
 
 seek ($position)
 

Protected Member Functions

 _getNextRow ()
 
- Protected Member Functions inherited from AbstractSource
 _getNextRow ()
 

Protected Attributes

 $_pattern = []
 
 $_dynamicColumns = []
 
 $_limit = 0
 
- Protected Attributes inherited from AbstractSource
 $_colNames = []
 
 $_colQty
 
 $_row = []
 
 $_key = -1
 
 $_foundWrongQuoteFlag = false
 

Detailed Description

Definition at line 14 of file Generator.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $rowPattern,
  $limit 
)

Read the row pattern to determine which columns are dynamic, set the collection size

Parameters
array$rowPattern
int$limithow many records to generate

Definition at line 41 of file Generator.php.

42  {
43  foreach ($rowPattern as $key => $value) {
44  if (is_callable($value) || is_string($value) && (false !== strpos($value, '%s'))) {
45  $this->_dynamicColumns[$key] = $value;
46  }
47  }
48  $this->_pattern = $rowPattern;
49  $this->_limit = (int)$limit;
50  parent::__construct(array_keys($rowPattern));
51  }
$value
Definition: gender.phtml:16

Member Function Documentation

◆ _getNextRow()

_getNextRow ( )
protected

Render next row

Return array or false on error

Returns
array|false

Definition at line 70 of file Generator.php.

71  {
73  foreach ($this->_dynamicColumns as $key => $dynamicValue) {
74  $index = $this->_key + 1;
75  if (is_callable($dynamicValue)) {
76  $row[$key] = call_user_func($dynamicValue, $index);
77  } else {
78  $row[$key] = str_replace('%s', $index, $dynamicValue);
79  }
80  }
81  return $row;
82  }
$index
Definition: list.phtml:44

◆ valid()

valid ( )

Whether limit of generated elements is reached (according to "Iterator" interface)

Returns
bool

Definition at line 58 of file Generator.php.

59  {
60  return $this->_key + 1 <= $this->_limit;
61  }

Field Documentation

◆ $_dynamicColumns

$_dynamicColumns = []
protected

Definition at line 28 of file Generator.php.

◆ $_limit

$_limit = 0
protected

Definition at line 33 of file Generator.php.

◆ $_pattern

$_pattern = []
protected

Definition at line 21 of file Generator.php.


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