Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Per the MikroTik API spec, Client treats empty tags as if no tag was …

…specified.

(Request and Communicator still differentiate between the two by design)
  • Loading branch information...
commit f00e59e733bae82133a1d1b63fead0006bc03862 1 parent f540144
@boenrobot boenrobot authored
Showing with 22 additions and 14 deletions.
  1. +14 −14 src/PEAR2/Net/RouterOS/Client.php
  2. +8 −0 tests/ClientFeaturesTest.php
View
28 src/PEAR2/Net/RouterOS/Client.php
@@ -103,7 +103,7 @@ public function __construct($host, $username, $password = '', $port = 8728,
);
//Login the user if necessary
if ($this->com->getTransmitter()->isFresh()) {
- if (!self::login($this->com, $username, $password)) {
+ if (!static::login($this->com, $username, $password)) {
$this->com->close();
throw new DataFlowException(
'Invalid username or password supplied.', 100
@@ -253,7 +253,7 @@ public function sendAsync(Request $request, $callback = null)
{
//Error checking
$tag = $request->getTag();
- if (null === $tag) {
+ if ('' == $tag) {
throw new DataFlowException(
'Asynchonous commands must have a tag.', 102
);
@@ -314,7 +314,7 @@ public function isRequestActive($tag, $filter = self::FILTER_ALL)
public function sendSync(Request $request)
{
$tag = $request->getTag();
- if (null === $tag) {
+ if ('' == $tag) {
$this->send($request);
} else {
$this->sendAsync($request);
@@ -338,19 +338,19 @@ public function sendSync(Request $request)
*/
public function completeRequest($tag = null)
{
- $isTagNull = null === $tag;
- $result = $isTagNull ? array()
+ $hasNoTag = '' == $tag;
+ $result = $hasNoTag ? array()
: $this->extractNewResponses($tag)->toArray();
- while ((!$isTagNull && $this->isRequestActive($tag))
- || ($isTagNull && 0 !== $this->getPendingRequestsCount())
+ while ((!$hasNoTag && $this->isRequestActive($tag))
+ || ($hasNoTag && 0 !== $this->getPendingRequestsCount())
) {
$newReply = $this->dispatchNextResponse();
if ($newReply->getTag() === $tag) {
- if ($isTagNull) {
+ if ($hasNoTag) {
$result[] = $newReply;
}
if ($newReply->getType() === Response::TYPE_FINAL) {
- if (!$isTagNull) {
+ if (!$hasNoTag) {
$result = array_merge(
$result,
$this->isRequestActive($tag)
@@ -380,7 +380,7 @@ public function completeRequest($tag = null)
*/
public function extractNewResponses($tag = null)
{
- if (null === $tag) {
+ if ('' == $tag) {
$result = array();
foreach (array_keys($this->responseBuffer) as $tag) {
$result = array_merge(
@@ -465,8 +465,8 @@ public function getPendingRequestsCount()
public function cancelRequest($tag = null)
{
$cancelRequest = new Request('/cancel');
- $tagIsNotNull = !(null === $tag);
- if ($tagIsNotNull) {
+ $hasTag = !('' == $tag);
+ if ($hasTag) {
if ($this->isRequestActive($tag)) {
$cancelRequest->setArgument('tag', $tag);
} else {
@@ -477,7 +477,7 @@ public function cancelRequest($tag = null)
}
$this->sendSync($cancelRequest);
- if ($tagIsNotNull) {
+ if ($hasTag) {
if ($this->isRequestActive($tag, self::FILTER_BUFFER)) {
unset($this->responseBuffer[$tag]);
} elseif ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
@@ -588,7 +588,7 @@ protected function dispatchNextResponse()
$this->pendingRequestsCount--;
}
- if (null !== $tag) {
+ if ('' != $tag) {
if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
if ($this->callbacks[$tag]($response, $this)) {
$this->cancelRequest($tag);
View
8 tests/ClientFeaturesTest.php
@@ -101,6 +101,14 @@ public function testSendAsyncTagRequirement()
} catch (DataFlowException $e) {
$this->assertEquals(102, $e->getCode(), 'Improper exception code.');
}
+ try {
+ $ping->setTag('');
+ $this->object->sendAsync($ping);
+
+ $this->fail('The call had to fail.');
+ } catch (DataFlowException $e) {
+ $this->assertEquals(102, $e->getCode(), 'Improper exception code.');
+ }
}
public function testSendAsyncUniqueTagRequirement()
Please sign in to comment.
Something went wrong with that request. Please try again.