From a7d68eaf1a0df1d954b4d6623ff0419a93739cd2 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 6 Mar 2014 13:13:01 +0100 Subject: Implement ArrayAccess interface for conveniently accessing rcube_result_set as array --- program/lib/Roundcube/rcube_result_set.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'program/lib/Roundcube/rcube_result_set.php') diff --git a/program/lib/Roundcube/rcube_result_set.php b/program/lib/Roundcube/rcube_result_set.php index a4b070e28..82502ce5f 100644 --- a/program/lib/Roundcube/rcube_result_set.php +++ b/program/lib/Roundcube/rcube_result_set.php @@ -25,7 +25,7 @@ * @package Framework * @subpackage Addressbook */ -class rcube_result_set implements Iterator +class rcube_result_set implements Iterator, ArrayAccess { public $count = 0; public $first = 0; @@ -61,6 +61,34 @@ class rcube_result_set implements Iterator $this->current = $i; } + /*** Implement PHP ArrayAccess interface ***/ + + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $offset = count($this->records); + $this->records[] = $value; + } + else { + $this->records[$offset] = $value; + } + } + + public function offsetExists($offset) + { + return isset($this->records[$offset]); + } + + public function offsetUnset($offset) + { + unset($this->records[$offset]); + } + + public function offsetGet($offset) + { + return $this->records[$offset]; + } + /*** PHP 5 Iterator interface ***/ function rewind() -- cgit v1.2.3