Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Iterator.php
Go to the documentation of this file.
1 <?php
11 
15 
17 {
27  public function walk($query, array $callbacks, array $args = [], $connection = null)
28  {
29  $stmt = $this->_getStatement($query, $connection);
30  $args['idx'] = 0;
31  while ($row = $stmt->fetch()) {
32  $args['row'] = $row;
33  foreach ($callbacks as $callback) {
34  $result = call_user_func($callback, $args);
35  if (!empty($result)) {
36  $args = array_merge($args, (array)$result);
37  }
38  }
39  $args['idx']++;
40  }
41 
42  return $this;
43  }
44 
53  protected function _getStatement($query, AdapterInterface $connection = null)
54  {
55  if ($query instanceof \Zend_Db_Statement_Interface) {
56  return $query;
57  }
58 
59  if ($query instanceof \Zend_Db_Select) {
60  return $query->query();
61  }
62 
63  if (is_string($query)) {
64  if (!$connection instanceof AdapterInterface) {
65  throw new LocalizedException(
66  new Phrase('The connection is invalid. Verify the connection and try again.')
67  );
68  }
69  return $connection->query($query);
70  }
71 
72  throw new LocalizedException(new Phrase('The query is invalid. Verify the query and try again.'));
73  }
74 }
walk($query, array $callbacks, array $args=[], $connection=null)
Definition: Iterator.php:27
_getStatement($query, AdapterInterface $connection=null)
Definition: Iterator.php:53
$connection
Definition: bulk.php:13