annotate plugins/libcalendaring/lib/Sabre/VObject/ElementList.php @ 4:888e774ee983

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