Mercurial > hg > rc1
comparison vendor/sabre/vobject/lib/ElementList.php @ 7:430dbd5346f7
vendor sabre as distributed
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 09:06:10 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:cec75ba50afc | 7:430dbd5346f7 |
---|---|
1 <?php | |
2 | |
3 namespace Sabre\VObject; | |
4 | |
5 /** | |
6 * VObject ElementList | |
7 * | |
8 * This class represents a list of elements. Lists are the result of queries, | |
9 * such as doing $vcalendar->vevent where there's multiple VEVENT objects. | |
10 * | |
11 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/). | |
12 * @author Evert Pot (http://evertpot.com/) | |
13 * @license http://sabre.io/license/ Modified BSD License | |
14 */ | |
15 class ElementList implements \Iterator, \Countable, \ArrayAccess { | |
16 | |
17 /** | |
18 * Inner elements | |
19 * | |
20 * @var array | |
21 */ | |
22 protected $elements = array(); | |
23 | |
24 /** | |
25 * Creates the element list. | |
26 * | |
27 * @param array $elements | |
28 */ | |
29 public function __construct(array $elements) { | |
30 | |
31 $this->elements = $elements; | |
32 | |
33 } | |
34 | |
35 /* {{{ Iterator interface */ | |
36 | |
37 /** | |
38 * Current position | |
39 * | |
40 * @var int | |
41 */ | |
42 private $key = 0; | |
43 | |
44 /** | |
45 * Returns current item in iteration | |
46 * | |
47 * @return Element | |
48 */ | |
49 public function current() { | |
50 | |
51 return $this->elements[$this->key]; | |
52 | |
53 } | |
54 | |
55 /** | |
56 * To the next item in the iterator | |
57 * | |
58 * @return void | |
59 */ | |
60 public function next() { | |
61 | |
62 $this->key++; | |
63 | |
64 } | |
65 | |
66 /** | |
67 * Returns the current iterator key | |
68 * | |
69 * @return int | |
70 */ | |
71 public function key() { | |
72 | |
73 return $this->key; | |
74 | |
75 } | |
76 | |
77 /** | |
78 * Returns true if the current position in the iterator is a valid one | |
79 * | |
80 * @return bool | |
81 */ | |
82 public function valid() { | |
83 | |
84 return isset($this->elements[$this->key]); | |
85 | |
86 } | |
87 | |
88 /** | |
89 * Rewinds the iterator | |
90 * | |
91 * @return void | |
92 */ | |
93 public function rewind() { | |
94 | |
95 $this->key = 0; | |
96 | |
97 } | |
98 | |
99 /* }}} */ | |
100 | |
101 /* {{{ Countable interface */ | |
102 | |
103 /** | |
104 * Returns the number of elements | |
105 * | |
106 * @return int | |
107 */ | |
108 public function count() { | |
109 | |
110 return count($this->elements); | |
111 | |
112 } | |
113 | |
114 /* }}} */ | |
115 | |
116 /* {{{ ArrayAccess Interface */ | |
117 | |
118 | |
119 /** | |
120 * Checks if an item exists through ArrayAccess. | |
121 * | |
122 * @param int $offset | |
123 * @return bool | |
124 */ | |
125 public function offsetExists($offset) { | |
126 | |
127 return isset($this->elements[$offset]); | |
128 | |
129 } | |
130 | |
131 /** | |
132 * Gets an item through ArrayAccess. | |
133 * | |
134 * @param int $offset | |
135 * @return mixed | |
136 */ | |
137 public function offsetGet($offset) { | |
138 | |
139 return $this->elements[$offset]; | |
140 | |
141 } | |
142 | |
143 /** | |
144 * Sets an item through ArrayAccess. | |
145 * | |
146 * @param int $offset | |
147 * @param mixed $value | |
148 * @return void | |
149 */ | |
150 public function offsetSet($offset, $value) { | |
151 | |
152 throw new \LogicException('You can not add new objects to an ElementList'); | |
153 | |
154 } | |
155 | |
156 /** | |
157 * Sets an item through ArrayAccess. | |
158 * | |
159 * This method just forwards the request to the inner iterator | |
160 * | |
161 * @param int $offset | |
162 * @return void | |
163 */ | |
164 public function offsetUnset($offset) { | |
165 | |
166 throw new \LogicException('You can not remove objects from an ElementList'); | |
167 | |
168 } | |
169 | |
170 /* }}} */ | |
171 | |
172 } |