Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Pattern.php
Go to the documentation of this file.
1 <?php
8 
14 class Pattern
15 {
21  protected $_headers;
22 
28  protected $_rowsSet;
29 
35  protected $_position = 0;
36 
44  public function setHeaders(array $headers)
45  {
46  $this->_headers = $headers;
47  return $this;
48  }
49 
55  public function getHeaders()
56  {
57  return $this->_headers;
58  }
59 
68  public function setRowsSet(array $rowsSet)
69  {
70  if (!count($rowsSet)) {
71  throw new \Exception("Rows set must contain at least 1 array representing a row pattern");
72  }
73  $this->_rowsSet = $rowsSet;
74  if (!isset($this->_headers)) {
75  $this->_headers = array_keys($rowsSet[0]);
76  }
77  return $this;
78  }
79 
87  public function addRow(array $row)
88  {
89  $this->_rowsSet[] = $row;
90  return $this;
91  }
92 
101  public function getRow($index, $generatorKey)
102  {
103  $row = $this->_rowsSet[$generatorKey % count($this->_rowsSet)];
104  foreach ($this->getHeaders() as $key) {
105  if (isset($row[$key])) {
106  if (is_callable($row[$key])) {
107  $row[$key] = call_user_func($row[$key], $index, $generatorKey);
108  } else {
109  $row[$key] = str_replace('%s', $index, $row[$key]);
110  }
111  } else {
112  $row[$key] = '';
113  }
114  }
115  return $row;
116  }
117 
123  public function getRowsCount()
124  {
125  return count($this->_rowsSet);
126  }
127 }
getRow($index, $generatorKey)
Definition: Pattern.php:101
$index
Definition: list.phtml:44