Browse Source

Options array added to all other short tags and some other methods

tags/1.3.2 1.3.2
Paul Rock 5 years ago
parent
commit
ba9abf49e6
  1. 18
      src/Client.php
  2. 9
      src/ResponseIterator.php
  3. 20
      src/ShortsTrait.php

18
src/Client.php

@ -226,8 +226,8 @@ class Client implements Interfaces\ClientInterface
/** /**
* Read RAW response from RouterOS, it can be /export command results also, not only array from API * Read RAW response from RouterOS, it can be /export command results also, not only array from API
* *
* @param array $options
*
* @param array $options Additional options
*
* @return array|string * @return array|string
* @since 1.0.0 * @since 1.0.0
*/ */
@ -251,7 +251,7 @@ class Client implements Interfaces\ClientInterface
$word = $this->connector->readWord(); $word = $this->connector->readWord();
//Limit response number to finish the read //Limit response number to finish the read
if (isset($options['count']) && $countResponse >= (int)$options['count']) {
if (isset($options['count']) && $countResponse >= (int) $options['count']) {
$lastReply = true; $lastReply = true;
} }
@ -295,8 +295,8 @@ class Client implements Interfaces\ClientInterface
* Reply ends with a complete !done or !fatal block (ended with 'empty line') * Reply ends with a complete !done or !fatal block (ended with 'empty line')
* A !fatal block precedes TCP connexion close * A !fatal block precedes TCP connexion close
* *
* @param bool $parse If need parse output to array
* @param array $options
* @param bool $parse If need parse output to array
* @param array $options Additional options
* *
* @return mixed * @return mixed
*/ */
@ -318,12 +318,14 @@ class Client implements Interfaces\ClientInterface
/** /**
* Read using Iterators to improve performance on large dataset * Read using Iterators to improve performance on large dataset
* *
* @param array $options Additional options
*
* @return \RouterOS\ResponseIterator * @return \RouterOS\ResponseIterator
* @since 1.0.0 * @since 1.0.0
*/ */
public function readAsIterator(): ResponseIterator
public function readAsIterator(array $options = []): ResponseIterator
{ {
return new ResponseIterator($this);
return new ResponseIterator($this, $options);
} }
/** /**
@ -336,7 +338,7 @@ class Client implements Interfaces\ClientInterface
* *
* Based on RouterOSResponseArray solution by @arily * Based on RouterOSResponseArray solution by @arily
* *
* @see https://github.com/arily/RouterOSResponseArray
* @see https://github.com/arily/RouterOSResponseArray
* @since 1.0.0 * @since 1.0.0
*/ */
private function rosario(array $raw): array private function rosario(array $raw): array

9
src/ResponseIterator.php

@ -59,9 +59,10 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable
/** /**
* ResponseIterator constructor. * ResponseIterator constructor.
* *
* @param Client $client
* @param \RouterOS\Client $client
* @param array $options Additional options
*/ */
public function __construct(Client $client)
public function __construct(Client $client, array $options = [])
{ {
// Set current to default // Set current to default
$this->rewind(); $this->rewind();
@ -70,9 +71,9 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable
$this->client = $client; $this->client = $client;
// Read RAW data from client // Read RAW data from client
$raw = $client->read(false);
$raw = $client->read(false, $options);
// This RAW should't be an error
// This RAW shouldn't be an error
$positions = array_keys($raw, '!re'); $positions = array_keys($raw, '!re');
$count = count($raw); $count = count($raw);
$result = []; $result = [];

20
src/ShortsTrait.php

@ -32,8 +32,8 @@ trait ShortsTrait
/** /**
* Alias for ->read() method * Alias for ->read() method
* *
* @param bool $parse If need parse output to array
* @param array $options
* @param bool $parse If need parse output to array
* @param array $options Additional options
* *
* @return mixed * @return mixed
* @since 0.7 * @since 0.7
@ -46,12 +46,14 @@ trait ShortsTrait
/** /**
* Alias for ->readAsIterator() method * Alias for ->readAsIterator() method
* *
* @param array $options Additional options
*
* @return \RouterOS\ResponseIterator * @return \RouterOS\ResponseIterator
* @since 1.0.0 * @since 1.0.0
*/ */
public function ri(): ResponseIterator
public function ri(array $options = []): ResponseIterator
{ {
return $this->readAsIterator();
return $this->readAsIterator($options);
} }
/** /**
@ -62,13 +64,14 @@ trait ShortsTrait
* @param string|null $operations Some operations which need make on response * @param string|null $operations Some operations which need make on response
* @param string|null $tag Mark query with tag * @param string|null $tag Mark query with tag
* @param bool $parse If need parse output to array * @param bool $parse If need parse output to array
* @param array $options Additional options
* *
* @return array * @return array
* @since 1.0.0 * @since 1.0.0
*/ */
public function qr($endpoint, array $where = null, string $operations = null, string $tag = null, bool $parse = true): array
public function qr($endpoint, array $where = null, string $operations = null, string $tag = null, bool $parse = true, array $options = []): array
{ {
return $this->query($endpoint, $where, $operations, $tag)->read($parse);
return $this->query($endpoint, $where, $operations, $tag)->read($parse, $options);
} }
/** /**
@ -78,12 +81,13 @@ trait ShortsTrait
* @param array|null $where List of where filters * @param array|null $where List of where filters
* @param string|null $operations Some operations which need make on response * @param string|null $operations Some operations which need make on response
* @param string|null $tag Mark query with tag * @param string|null $tag Mark query with tag
* @param array $options Additional options
* *
* @return \RouterOS\ResponseIterator * @return \RouterOS\ResponseIterator
* @since 1.0.0 * @since 1.0.0
*/ */
public function qri($endpoint, array $where = null, string $operations = null, string $tag = null): ResponseIterator
public function qri($endpoint, array $where = null, string $operations = null, string $tag = null, array $options = []): ResponseIterator
{ {
return $this->query($endpoint, $where, $operations, $tag)->readAsIterator();
return $this->query($endpoint, $where, $operations, $tag)->readAsIterator($options);
} }
} }
Loading…
Cancel
Save