annotate plugins/libcalendaring/lib/Sabre/VObject/Node.php @ 30:7498e7cacd71

better error message
author Charlie Root
date Tue, 13 Mar 2018 12:59:17 -0400
parents 888e774ee983
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 * Base class for all nodes
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * The following constants are used by the validate() method.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 const REPAIR = 1;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * Turns the object back into a serialized blob.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * @return string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 abstract function serialize();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 * Iterator override
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 * @var ElementList
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 protected $iterator = null;
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 * A link to the parent node
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 * @var Node
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 public $parent = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 * Validates the node for correctness.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 * The following options are supported:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 * - Node::REPAIR - If something is broken, and automatic repair may
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 * be attempted.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 * An array is returned with warnings.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 * Every item in the array has the following properties:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 * * level - (number between 1 and 3 with severity information)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 * * message - (human readable message)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 * * node - (reference to the offending node)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 * @param int $options
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 * @return array
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 public function validate($options = 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 return array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 /* {{{ IteratorAggregator interface */
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 * Returns the iterator for this object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 * @return ElementList
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 public function getIterator() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 if (!is_null($this->iterator))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 return $this->iterator;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 return new ElementList(array($this));
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
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 * Sets the overridden iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 * Note that this is not actually part of the iterator interface
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 * @param ElementList $iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 public function setIterator(ElementList $iterator) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 $this->iterator = $iterator;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 /* }}} */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 /* {{{ Countable interface */
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 * Returns the number of elements
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 * @return int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 public function count() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 $it = $this->getIterator();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 return $it->count();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 /* }}} */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 /* {{{ ArrayAccess Interface */
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 * Checks if an item exists through ArrayAccess.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117 * This method just forwards the request to the inner iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 * @param int $offset
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 public function offsetExists($offset) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 $iterator = $this->getIterator();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 return $iterator->offsetExists($offset);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 }
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 * Gets an item through ArrayAccess.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 * This method just forwards the request to the inner iterator
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 $iterator = $this->getIterator();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 return $iterator->offsetGet($offset);
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 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 * Sets an item through ArrayAccess.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 * This method just forwards the request to the inner iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 * @param int $offset
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 * @param mixed $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 public function offsetSet($offset,$value) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 $iterator = $this->getIterator();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 $iterator->offsetSet($offset,$value);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 // @codeCoverageIgnoreStart
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 // This method always throws an exception, so we ignore the closing
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 // brace
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 // @codeCoverageIgnoreEnd
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 * Sets an item through ArrayAccess.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 * This method just forwards the request to the inner iterator
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 * @param int $offset
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 public function offsetUnset($offset) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 $iterator = $this->getIterator();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 $iterator->offsetUnset($offset);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 // @codeCoverageIgnoreStart
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 // This method always throws an exception, so we ignore the closing
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 // brace
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183 // @codeCoverageIgnoreEnd
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185 /* }}} */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 }