Skip to content

Commit 9d237d4

Browse files
committed
Added ResponseCollection::prev().
1 parent 81c0a78 commit 9d237d4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

RELEASE-1.0.0b2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A lot of new conviniences and a few bug fixes.
44
* Added support for CLI argument syntax at Request constructor.
55
* Added optional arguments to request constructor for a tag and a query.
66
* Added Communicator::isSeekableStream() and made Communicator::sendWordFromStream() use it.
7-
* Added ResponseCollection::end().
7+
* Added ResponseCollection::prev() and ResponseCollection::end().
88
* Changed the default value of the $value of Message::setArgument from NULL to an empty string.
99
* Changed ResponseCollection::getLast() to return FALSE when the collection is empty.
1010
* Changed Request::setArgument() so that any invalid value is casted to string.

src/PEAR2/Net/RouterOS/ResponseCollection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ public function current()
219219
return $this->valid() ? $this->responses[$this->position] : false;
220220
}
221221

222+
/**
223+
* Moves the pointer backwards by 1, and gets the previous response.
224+
*
225+
* @return Response The next {@link Response} object, or FALSE if the
226+
* position is not valid.
227+
*/
228+
public function prev()
229+
{
230+
--$this->position;
231+
return $this->current();
232+
}
233+
222234
/**
223235
* Moves the pointer to the last valid position, and returns the last
224236
* response.

tests/ClientFeaturesTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public function testSendSyncReturningCollection()
3434
__NAMESPACE__ . '\Response', $list->end(),
3535
'The list is empty'
3636
);
37+
$this->assertEquals(Response::TYPE_FINAL, $list->current()->getType());
38+
$this->assertInstanceOf(
39+
__NAMESPACE__ . '\Response', $list->prev(),
40+
'The list is empty'
41+
);
42+
$this->assertEquals(Response::TYPE_DATA, $list->current()->getType());
3743
}
3844

3945
public function testSendSyncReturningCollectionWithStreams()

0 commit comments

Comments
 (0)