From ba9abf49e6fae33b9df300667e8679eb34124a55 Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Mon, 30 Nov 2020 21:18:15 +0300 Subject: [PATCH] Options array added to all other short tags and some other methods --- src/Client.php | 18 ++++++++++-------- src/ResponseIterator.php | 9 +++++---- src/ShortsTrait.php | 20 ++++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Client.php b/src/Client.php index 796fb32..ba714a9 100644 --- a/src/Client.php +++ b/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 * - * @param array $options - * + * @param array $options Additional options + * * @return array|string * @since 1.0.0 */ @@ -251,7 +251,7 @@ class Client implements Interfaces\ClientInterface $word = $this->connector->readWord(); //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; } @@ -295,8 +295,8 @@ class Client implements Interfaces\ClientInterface * Reply ends with a complete !done or !fatal block (ended with 'empty line') * 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 */ @@ -318,12 +318,14 @@ class Client implements Interfaces\ClientInterface /** * Read using Iterators to improve performance on large dataset * + * @param array $options Additional options + * * @return \RouterOS\ResponseIterator * @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 * - * @see https://github.com/arily/RouterOSResponseArray + * @see https://github.com/arily/RouterOSResponseArray * @since 1.0.0 */ private function rosario(array $raw): array diff --git a/src/ResponseIterator.php b/src/ResponseIterator.php index 2ed95be..f61ede7 100644 --- a/src/ResponseIterator.php +++ b/src/ResponseIterator.php @@ -59,9 +59,10 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable /** * 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 $this->rewind(); @@ -70,9 +71,9 @@ class ResponseIterator implements Iterator, ArrayAccess, Countable, Serializable $this->client = $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'); $count = count($raw); $result = []; diff --git a/src/ShortsTrait.php b/src/ShortsTrait.php index 9495cf1..784af6a 100644 --- a/src/ShortsTrait.php +++ b/src/ShortsTrait.php @@ -32,8 +32,8 @@ trait ShortsTrait /** * 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 * @since 0.7 @@ -46,12 +46,14 @@ trait ShortsTrait /** * Alias for ->readAsIterator() method * + * @param array $options Additional options + * * @return \RouterOS\ResponseIterator * @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 $tag Mark query with tag * @param bool $parse If need parse output to array + * @param array $options Additional options * * @return array * @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 string|null $operations Some operations which need make on response * @param string|null $tag Mark query with tag + * @param array $options Additional options * * @return \RouterOS\ResponseIterator * @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); } }