|
|
@ -226,15 +226,19 @@ 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 |
|
|
|
|
|
* |
|
|
* @return array|string |
|
|
* @return array|string |
|
|
* @since 1.0.0 |
|
|
* @since 1.0.0 |
|
|
*/ |
|
|
*/ |
|
|
public function readRAW() |
|
|
|
|
|
|
|
|
public function readRAW(array $options = []) |
|
|
{ |
|
|
{ |
|
|
// By default response is empty
|
|
|
// By default response is empty
|
|
|
$response = []; |
|
|
$response = []; |
|
|
// We have to wait a !done or !fatal
|
|
|
// We have to wait a !done or !fatal
|
|
|
$lastReply = false; |
|
|
$lastReply = false; |
|
|
|
|
|
// Count !re in response
|
|
|
|
|
|
$countResponse = 0; |
|
|
|
|
|
|
|
|
// Convert strings to array and return results
|
|
|
// Convert strings to array and return results
|
|
|
if ($this->isCustomOutput()) { |
|
|
if ($this->isCustomOutput()) { |
|
|
@ -246,6 +250,11 @@ class Client implements Interfaces\ClientInterface |
|
|
while (true) { |
|
|
while (true) { |
|
|
$word = $this->connector->readWord(); |
|
|
$word = $this->connector->readWord(); |
|
|
|
|
|
|
|
|
|
|
|
//Limit response number to finish the read
|
|
|
|
|
|
if (isset($options['count']) && $countResponse >= (int)$options['count']) { |
|
|
|
|
|
$lastReply = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if ('' === $word) { |
|
|
if ('' === $word) { |
|
|
if ($lastReply) { |
|
|
if ($lastReply) { |
|
|
// We received a !done or !fatal message in a precedent loop
|
|
|
// We received a !done or !fatal message in a precedent loop
|
|
|
@ -266,6 +275,11 @@ class Client implements Interfaces\ClientInterface |
|
|
if ('!done' === $word || '!fatal' === $word) { |
|
|
if ('!done' === $word || '!fatal' === $word) { |
|
|
$lastReply = true; |
|
|
$lastReply = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If we get a !re line in response, we increment the variable
|
|
|
|
|
|
if ('!re' === $word) { |
|
|
|
|
|
$countResponse++; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Parse results and return
|
|
|
// Parse results and return
|
|
|
@ -282,13 +296,14 @@ class Client implements Interfaces\ClientInterface |
|
|
* A !fatal block precedes TCP connexion close |
|
|
* A !fatal block precedes TCP connexion close |
|
|
* |
|
|
* |
|
|
* @param bool $parse If need parse output to array |
|
|
* @param bool $parse If need parse output to array |
|
|
|
|
|
* @param array $options |
|
|
* |
|
|
* |
|
|
* @return mixed |
|
|
* @return mixed |
|
|
*/ |
|
|
*/ |
|
|
public function read(bool $parse = true) |
|
|
|
|
|
|
|
|
public function read(bool $parse = true, array $options = []) |
|
|
{ |
|
|
{ |
|
|
// Read RAW response
|
|
|
// Read RAW response
|
|
|
$response = $this->readRAW(); |
|
|
|
|
|
|
|
|
$response = $this->readRAW($options); |
|
|
|
|
|
|
|
|
// Return RAW configuration if custom output is set
|
|
|
// Return RAW configuration if custom output is set
|
|
|
if ($this->isCustomOutput()) { |
|
|
if ($this->isCustomOutput()) { |
|
|
|