6 * This class represents a list of elements. Lists are the result of queries,
7 * such as doing $vcalendar->vevent where there's multiple VEVENT objects.
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15 class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
22 protected $elements = array();
25 * Creates the element list.
27 * @param array $elements
29 public function __construct(array $elements) {
31 $this->elements = $elements;
35 /* {{{ Iterator interface */
45 * Returns current item in iteration
47 * @return Sabre_VObject_Element
49 public function current() {
51 return $this->elements[$this->key];
56 * To the next item in the iterator
60 public function next() {
67 * Returns the current iterator key
71 public function key() {
78 * Returns true if the current position in the iterator is a valid one
82 public function valid() {
84 return isset($this->elements[$this->key]);
89 * Rewinds the iterator
93 public function rewind() {
101 /* {{{ Countable interface */
104 * Returns the number of elements
108 public function count() {
110 return count($this->elements);
116 /* {{{ ArrayAccess Interface */
120 * Checks if an item exists through ArrayAccess.
125 public function offsetExists($offset) {
127 return isset($this->elements[$offset]);
132 * Gets an item through ArrayAccess.
137 public function offsetGet($offset) {
139 return $this->elements[$offset];
144 * Sets an item through ArrayAccess.
147 * @param mixed $value
150 public function offsetSet($offset,$value) {
152 throw new LogicException('You can not add new objects to an ElementList');
157 * Sets an item through ArrayAccess.
159 * This method just forwards the request to the inner iterator
164 public function offsetUnset($offset) {
166 throw new LogicException('You can not remove objects from an ElementList');