Browse Source

Iterator

pull/14/head
arily 6 years ago
parent
commit
21fbe6fcf5
  1. BIN
      src/.DS_Store
  2. 6
      src/Client.php
  3. 16
      src/Iterators/ResponseIterator.php

BIN
src/.DS_Store

6
src/Client.php

@ -177,6 +177,7 @@ class Client implements Interfaces\ClientInterface
}
<<<<<<< HEAD
/**
* Read using Iterators to improve performance on large dataset
*
@ -185,6 +186,11 @@ class Client implements Interfaces\ClientInterface
public function readAsIterator()
{
return new Iterators\ResponseIterator($this->read(false));
=======
public function readAsIterators()
{
return new Iterators\ResponseIterator($this->rosario($this->read(false)));
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
}
/**

16
src/Iterators/ResponseIterator.php

@ -9,20 +9,29 @@
namespace RouterOS\Iterators;
<<<<<<< HEAD
/**
* Class ResponseIterator
* @package RouterOS\Iterators
*/
=======
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
class ResponseIterator implements \Iterator, \ArrayAccess, \Countable {
public $parsed = [];
public $raw = [];
public $current;
<<<<<<< HEAD
public $length;
=======
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
public function __construct($raw) {
$this->current = 0;
// This RAW should't be an error
$positions = array_keys($raw, '!re');
<<<<<<< HEAD
$this->length = count($positions);
=======
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
$count = count($raw);
$result = [];
@ -35,7 +44,14 @@ class ResponseIterator implements \Iterator, \ArrayAccess, \Countable {
: $count - $position;
// Convert array to simple items
<<<<<<< HEAD
$item = array_slice($raw,$position,$length);
=======
$item = [];
for ($i = 1; $i < $length; $i++) {
$item[] = array_shift($raw);
}
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
// Save as result
$result[] = $item;

Loading…
Cancel
Save