Browse Source

add options in read method to commands that have multiple responses

pull/46/head
Diogo Bemfica 5 years ago
parent
commit
17f0a377ae
  1. 2
      README.md
  2. 2
      composer.json
  3. 18
      src/Client.php

2
README.md

@ -8,7 +8,7 @@
# RouterOS API Client
composer require evilfreelancer/routeros-api-php
composer require proner/routeros-api-php
This library is partly based on [this old project](https://github.com/BenMenking/routeros-api), but unlike it has many
innovations to ease development. In addition, the project is designed

2
composer.json

@ -1,5 +1,5 @@
{
"name": "evilfreelancer/routeros-api-php",
"name": "proner/routeros-api-php",
"type": "library",
"description": "Modern Mikrotik RouterOS API PHP client for your applications (with Laravel support)",
"keywords": [

18
src/Client.php

@ -229,12 +229,14 @@ class Client implements Interfaces\ClientInterface
* @return array|string
* @since 1.0.0
*/
public function readRAW()
public function readRAW(array $options = [])
{
// By default response is empty
$response = [];
// We have to wait a !done or !fatal
$lastReply = false;
// Count !re in response
$countResponse = 0;
// Convert strings to array and return results
if ($this->isCustomOutput()) {
@ -246,6 +248,11 @@ class Client implements Interfaces\ClientInterface
while (true) {
$word = $this->connector->readWord();
//Limit response number to finish the read
if (isset($options['count']) && $countResponse >= (int)$options['count']) {
$lastReply = true;
}
if ('' === $word) {
if ($lastReply) {
// We received a !done or !fatal message in a precedent loop
@ -266,6 +273,11 @@ class Client implements Interfaces\ClientInterface
if ('!done' === $word || '!fatal' === $word) {
$lastReply = true;
}
// If we get a !re line in response, we increment the variable
if ('!re' === $word) {
$countResponse++;
}
}
// Parse results and return
@ -285,10 +297,10 @@ class Client implements Interfaces\ClientInterface
*
* @return mixed
*/
public function read(bool $parse = true)
public function read(bool $parse = true, array $options = [])
{
// Read RAW response
$response = $this->readRAW();
$response = $this->readRAW($options);
// Return RAW configuration if custom output is set
if ($this->isCustomOutput()) {

Loading…
Cancel
Save