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 * Read using Iterators to improve performance on large dataset
* *
@ -185,6 +186,11 @@ class Client implements Interfaces\ClientInterface
public function readAsIterator() public function readAsIterator()
{ {
return new Iterators\ResponseIterator($this->read(false)); 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; namespace RouterOS\Iterators;
<<<<<<< HEAD
/** /**
* Class ResponseIterator * Class ResponseIterator
* @package RouterOS\Iterators * @package RouterOS\Iterators
*/ */
=======
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
class ResponseIterator implements \Iterator, \ArrayAccess, \Countable { class ResponseIterator implements \Iterator, \ArrayAccess, \Countable {
public $parsed = []; public $parsed = [];
public $raw = []; public $raw = [];
public $current; public $current;
<<<<<<< HEAD
public $length; public $length;
=======
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
public function __construct($raw) { public function __construct($raw) {
$this->current = 0; $this->current = 0;
// This RAW should't be an error // This RAW should't be an error
$positions = array_keys($raw, '!re'); $positions = array_keys($raw, '!re');
<<<<<<< HEAD
$this->length = count($positions); $this->length = count($positions);
=======
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
$count = count($raw); $count = count($raw);
$result = []; $result = [];
@ -35,7 +44,14 @@ class ResponseIterator implements \Iterator, \ArrayAccess, \Countable {
: $count - $position; : $count - $position;
// Convert array to simple items // Convert array to simple items
<<<<<<< HEAD
$item = array_slice($raw,$position,$length); $item = array_slice($raw,$position,$length);
=======
$item = [];
for ($i = 1; $i < $length; $i++) {
$item[] = array_shift($raw);
}
>>>>>>> ccd0d5054aa39ec1c1fa9fdfa26988f4f0d53053
// Save as result // Save as result
$result[] = $item; $result[] = $item;

Loading…
Cancel
Save