Skip to content
This repository
Browse code

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
Vasil Rangelov authored February 01, 2012
28  src/PEAR2/Net/RouterOS/Client.php
@@ -103,7 +103,7 @@ public function __construct($host, $username, $password = '', $port = 8728,
103 103
         );
104 104
         //Login the user if necessary
105 105
         if ($this->com->getTransmitter()->isFresh()) {
106  
-            if (!self::login($this->com, $username, $password)) {
  106
+            if (!static::login($this->com, $username, $password)) {
107 107
                 $this->com->close();
108 108
                 throw new DataFlowException(
109 109
                     'Invalid username or password supplied.', 100
@@ -253,7 +253,7 @@ public function sendAsync(Request $request, $callback = null)
253 253
     {
254 254
         //Error checking
255 255
         $tag = $request->getTag();
256  
-        if (null === $tag) {
  256
+        if ('' == $tag) {
257 257
             throw new DataFlowException(
258 258
                 'Asynchonous commands must have a tag.', 102
259 259
             );
@@ -314,7 +314,7 @@ public function isRequestActive($tag, $filter = self::FILTER_ALL)
314 314
     public function sendSync(Request $request)
315 315
     {
316 316
         $tag = $request->getTag();
317  
-        if (null === $tag) {
  317
+        if ('' == $tag) {
318 318
             $this->send($request);
319 319
         } else {
320 320
             $this->sendAsync($request);
@@ -338,19 +338,19 @@ public function sendSync(Request $request)
338 338
      */
339 339
     public function completeRequest($tag = null)
340 340
     {
341  
-        $isTagNull = null === $tag;
342  
-        $result = $isTagNull ? array()
  341
+        $hasNoTag = '' == $tag;
  342
+        $result = $hasNoTag ? array()
343 343
             : $this->extractNewResponses($tag)->toArray();
344  
-        while ((!$isTagNull && $this->isRequestActive($tag))
345  
-        || ($isTagNull && 0 !== $this->getPendingRequestsCount())
  344
+        while ((!$hasNoTag && $this->isRequestActive($tag))
  345
+        || ($hasNoTag && 0 !== $this->getPendingRequestsCount())
346 346
         ) {
347 347
             $newReply = $this->dispatchNextResponse();
348 348
             if ($newReply->getTag() === $tag) {
349  
-                if ($isTagNull) {
  349
+                if ($hasNoTag) {
350 350
                     $result[] = $newReply;
351 351
                 }
352 352
                 if ($newReply->getType() === Response::TYPE_FINAL) {
353  
-                    if (!$isTagNull) {
  353
+                    if (!$hasNoTag) {
354 354
                         $result = array_merge(
355 355
                             $result,
356 356
                             $this->isRequestActive($tag)
@@ -380,7 +380,7 @@ public function completeRequest($tag = null)
380 380
      */
381 381
     public function extractNewResponses($tag = null)
382 382
     {
383  
-        if (null === $tag) {
  383
+        if ('' == $tag) {
384 384
             $result = array();
385 385
             foreach (array_keys($this->responseBuffer) as $tag) {
386 386
                 $result = array_merge(
@@ -465,8 +465,8 @@ public function getPendingRequestsCount()
465 465
     public function cancelRequest($tag = null)
466 466
     {
467 467
         $cancelRequest = new Request('/cancel');
468  
-        $tagIsNotNull = !(null === $tag);
469  
-        if ($tagIsNotNull) {
  468
+        $hasTag = !('' == $tag);
  469
+        if ($hasTag) {
470 470
             if ($this->isRequestActive($tag)) {
471 471
                 $cancelRequest->setArgument('tag', $tag);
472 472
             } else {
@@ -477,7 +477,7 @@ public function cancelRequest($tag = null)
477 477
         }
478 478
         $this->sendSync($cancelRequest);
479 479
 
480  
-        if ($tagIsNotNull) {
  480
+        if ($hasTag) {
481 481
             if ($this->isRequestActive($tag, self::FILTER_BUFFER)) {
482 482
                 unset($this->responseBuffer[$tag]);
483 483
             } elseif ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
@@ -588,7 +588,7 @@ protected function dispatchNextResponse()
588 588
             $this->pendingRequestsCount--;
589 589
         }
590 590
 
591  
-        if (null !== $tag) {
  591
+        if ('' != $tag) {
592 592
             if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
593 593
                 if ($this->callbacks[$tag]($response, $this)) {
594 594
                     $this->cancelRequest($tag);
8  tests/ClientFeaturesTest.php
@@ -101,6 +101,14 @@ public function testSendAsyncTagRequirement()
101 101
         } catch (DataFlowException $e) {
102 102
             $this->assertEquals(102, $e->getCode(), 'Improper exception code.');
103 103
         }
  104
+        try {
  105
+            $ping->setTag('');
  106
+            $this->object->sendAsync($ping);
  107
+
  108
+            $this->fail('The call had to fail.');
  109
+        } catch (DataFlowException $e) {
  110
+            $this->assertEquals(102, $e->getCode(), 'Improper exception code.');
  111
+        }
104 112
     }
105 113
 
106 114
     public function testSendAsyncUniqueTagRequirement()

0 notes on commit f00e59e

Please sign in to comment.
Something went wrong with that request. Please try again.