Component
6 months ago
ITip
6 months ago
Parser
6 months ago
Property
6 months ago
Recur
6 months ago
Splitter
6 months ago
TimezoneGuesser
6 months ago
timezonedata
1 year ago
BirthdayCalendarGenerator.php
6 months ago
Cli.php
6 months ago
Component.php
6 months ago
DateTimeParser.php
6 months ago
Document.php
6 months ago
ElementList.php
6 months ago
EofException.php
6 months ago
FreeBusyData.php
6 months ago
FreeBusyGenerator.php
6 months ago
InvalidDataException.php
6 months ago
Node.php
6 months ago
PHPUnitAssertions.php
6 months ago
Parameter.php
6 months ago
ParseException.php
6 months ago
Property.php
6 months ago
Reader.php
6 months ago
Settings.php
6 months ago
StringUtil.php
6 months ago
TimeZoneUtil.php
6 months ago
UUIDUtil.php
6 months ago
VCardConverter.php
6 months ago
Version.php
6 months ago
Writer.php
6 months ago
Node.php
253 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject; |
| 4 | |
| 5 | use AmeliaVendor\Sabre\Xml; |
| 6 | |
| 7 | /** |
| 8 | * A node is the root class for every element in an iCalendar of vCard object. |
| 9 | * |
| 10 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 11 | * @author Evert Pot (http://evertpot.com/) |
| 12 | * @license http://sabre.io/license/ Modified BSD License |
| 13 | */ |
| 14 | abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable, Xml\XmlSerializable |
| 15 | { |
| 16 | /** |
| 17 | * The following constants are used by the validate() method. |
| 18 | * |
| 19 | * If REPAIR is set, the validator will attempt to repair any broken data |
| 20 | * (if possible). |
| 21 | */ |
| 22 | const REPAIR = 1; |
| 23 | |
| 24 | /** |
| 25 | * If this option is set, the validator will operate on the vcards on the |
| 26 | * assumption that the vcards need to be valid for CardDAV. |
| 27 | * |
| 28 | * This means for example that the UID is required, whereas it is not for |
| 29 | * regular vcards. |
| 30 | */ |
| 31 | const PROFILE_CARDDAV = 2; |
| 32 | |
| 33 | /** |
| 34 | * If this option is set, the validator will operate on iCalendar objects |
| 35 | * on the assumption that the vcards need to be valid for CalDAV. |
| 36 | * |
| 37 | * This means for example that calendars can only contain objects with |
| 38 | * identical component types and UIDs. |
| 39 | */ |
| 40 | const PROFILE_CALDAV = 4; |
| 41 | |
| 42 | /** |
| 43 | * Reference to the parent object, if this is not the top object. |
| 44 | * |
| 45 | * @var Node |
| 46 | */ |
| 47 | public $parent; |
| 48 | |
| 49 | /** |
| 50 | * Iterator override. |
| 51 | * |
| 52 | * @var ElementList |
| 53 | */ |
| 54 | protected $iterator = null; |
| 55 | |
| 56 | /** |
| 57 | * The root document. |
| 58 | * |
| 59 | * @var Component |
| 60 | */ |
| 61 | protected $root; |
| 62 | |
| 63 | /** |
| 64 | * Serializes the node into a mimedir format. |
| 65 | * |
| 66 | * @return string |
| 67 | */ |
| 68 | abstract public function serialize(); |
| 69 | |
| 70 | /** |
| 71 | * This method returns an array, with the representation as it should be |
| 72 | * encoded in JSON. This is used to create jCard or jCal documents. |
| 73 | * |
| 74 | * @return array |
| 75 | */ |
| 76 | #[\ReturnTypeWillChange] |
| 77 | abstract public function jsonSerialize(); |
| 78 | |
| 79 | /** |
| 80 | * This method serializes the data into XML. This is used to create xCard or |
| 81 | * xCal documents. |
| 82 | * |
| 83 | * @param Xml\Writer $writer XML writer |
| 84 | */ |
| 85 | abstract public function xmlSerialize(Xml\Writer $writer): void; |
| 86 | |
| 87 | /** |
| 88 | * Call this method on a document if you're done using it. |
| 89 | * |
| 90 | * It's intended to remove all circular references, so PHP can easily clean |
| 91 | * it up. |
| 92 | */ |
| 93 | public function destroy() |
| 94 | { |
| 95 | $this->parent = null; |
| 96 | $this->root = null; |
| 97 | } |
| 98 | |
| 99 | /* {{{ IteratorAggregator interface */ |
| 100 | |
| 101 | /** |
| 102 | * Returns the iterator for this object. |
| 103 | * |
| 104 | * @return ElementList |
| 105 | */ |
| 106 | #[\ReturnTypeWillChange] |
| 107 | public function getIterator() |
| 108 | { |
| 109 | if (!is_null($this->iterator)) { |
| 110 | return $this->iterator; |
| 111 | } |
| 112 | |
| 113 | return new ElementList([$this]); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the overridden iterator. |
| 118 | * |
| 119 | * Note that this is not actually part of the iterator interface |
| 120 | */ |
| 121 | public function setIterator(ElementList $iterator) |
| 122 | { |
| 123 | $this->iterator = $iterator; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Validates the node for correctness. |
| 128 | * |
| 129 | * The following options are supported: |
| 130 | * Node::REPAIR - May attempt to automatically repair the problem. |
| 131 | * |
| 132 | * This method returns an array with detected problems. |
| 133 | * Every element has the following properties: |
| 134 | * |
| 135 | * * level - problem level. |
| 136 | * * message - A human-readable string describing the issue. |
| 137 | * * node - A reference to the problematic node. |
| 138 | * |
| 139 | * The level means: |
| 140 | * 1 - The issue was repaired (only happens if REPAIR was turned on) |
| 141 | * 2 - An inconsequential issue |
| 142 | * 3 - A severe issue. |
| 143 | * |
| 144 | * @param int $options |
| 145 | * |
| 146 | * @return array |
| 147 | */ |
| 148 | public function validate($options = 0) |
| 149 | { |
| 150 | return []; |
| 151 | } |
| 152 | |
| 153 | /* }}} */ |
| 154 | |
| 155 | /* {{{ Countable interface */ |
| 156 | |
| 157 | /** |
| 158 | * Returns the number of elements. |
| 159 | * |
| 160 | * @return int |
| 161 | */ |
| 162 | #[\ReturnTypeWillChange] |
| 163 | public function count() |
| 164 | { |
| 165 | $it = $this->getIterator(); |
| 166 | |
| 167 | return $it->count(); |
| 168 | } |
| 169 | |
| 170 | /* }}} */ |
| 171 | |
| 172 | /* {{{ ArrayAccess Interface */ |
| 173 | |
| 174 | /** |
| 175 | * Checks if an item exists through ArrayAccess. |
| 176 | * |
| 177 | * This method just forwards the request to the inner iterator |
| 178 | * |
| 179 | * @param int $offset |
| 180 | * |
| 181 | * @return bool |
| 182 | */ |
| 183 | #[\ReturnTypeWillChange] |
| 184 | public function offsetExists($offset) |
| 185 | { |
| 186 | $iterator = $this->getIterator(); |
| 187 | |
| 188 | return $iterator->offsetExists($offset); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Gets an item through ArrayAccess. |
| 193 | * |
| 194 | * This method just forwards the request to the inner iterator |
| 195 | * |
| 196 | * @param int $offset |
| 197 | * |
| 198 | * @return mixed |
| 199 | */ |
| 200 | #[\ReturnTypeWillChange] |
| 201 | public function offsetGet($offset) |
| 202 | { |
| 203 | $iterator = $this->getIterator(); |
| 204 | |
| 205 | return $iterator->offsetGet($offset); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Sets an item through ArrayAccess. |
| 210 | * |
| 211 | * This method just forwards the request to the inner iterator |
| 212 | * |
| 213 | * @param int $offset |
| 214 | * @param mixed $value |
| 215 | */ |
| 216 | #[\ReturnTypeWillChange] |
| 217 | public function offsetSet($offset, $value) |
| 218 | { |
| 219 | $iterator = $this->getIterator(); |
| 220 | $iterator->offsetSet($offset, $value); |
| 221 | |
| 222 | // @codeCoverageIgnoreStart |
| 223 | // |
| 224 | // This method always throws an exception, so we ignore the closing |
| 225 | // brace |
| 226 | } |
| 227 | |
| 228 | // @codeCoverageIgnoreEnd |
| 229 | |
| 230 | /** |
| 231 | * Sets an item through ArrayAccess. |
| 232 | * |
| 233 | * This method just forwards the request to the inner iterator |
| 234 | * |
| 235 | * @param int $offset |
| 236 | */ |
| 237 | #[\ReturnTypeWillChange] |
| 238 | public function offsetUnset($offset) |
| 239 | { |
| 240 | $iterator = $this->getIterator(); |
| 241 | $iterator->offsetUnset($offset); |
| 242 | |
| 243 | // @codeCoverageIgnoreStart |
| 244 | // |
| 245 | // This method always throws an exception, so we ignore the closing |
| 246 | // brace |
| 247 | } |
| 248 | |
| 249 | // @codeCoverageIgnoreEnd |
| 250 | |
| 251 | /* }}} */ |
| 252 | } |
| 253 |