]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/VObject/Node.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / VObject / Node.php
1 <?php
2
3 /**
4  * Base class for all nodes
5  *
6  * @package Sabre
7  * @subpackage VObject
8  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9  * @author Evert Pot (http://www.rooftopsolutions.nl/)
10  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11  */
12 abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Countable {
13
14     /**
15      * Turns the object back into a serialized blob.
16      *
17      * @return string
18      */
19     abstract function serialize();
20
21     /**
22      * Iterator override
23      *
24      * @var Sabre_VObject_ElementList
25      */
26     protected $iterator = null;
27
28     /**
29      * A link to the parent node
30      *
31      * @var Sabre_VObject_Node
32      */
33     public $parent = null;
34
35     /**
36      * Validates the node for correctness.
37      * An array is returned with warnings.
38      *
39      * Every item in the array has the following properties:
40      *    * level - (number between 1 and 3 with severity information)
41      *    * message - (human readable message)
42      *    * node - (reference to the offending node)
43      *
44      * @return array
45      */
46     public function validate() {
47
48         return array();
49
50     }
51
52     /* {{{ IteratorAggregator interface */
53
54     /**
55      * Returns the iterator for this object
56      *
57      * @return Sabre_VObject_ElementList
58      */
59     public function getIterator() {
60
61         if (!is_null($this->iterator))
62             return $this->iterator;
63
64         return new Sabre_VObject_ElementList(array($this));
65
66     }
67
68     /**
69      * Sets the overridden iterator
70      *
71      * Note that this is not actually part of the iterator interface
72      *
73      * @param Sabre_VObject_ElementList $iterator
74      * @return void
75      */
76     public function setIterator(Sabre_VObject_ElementList $iterator) {
77
78         $this->iterator = $iterator;
79
80     }
81
82     /* }}} */
83
84     /* {{{ Countable interface */
85
86     /**
87      * Returns the number of elements
88      *
89      * @return int
90      */
91     public function count() {
92
93         $it = $this->getIterator();
94         return $it->count();
95
96     }
97
98     /* }}} */
99
100     /* {{{ ArrayAccess Interface */
101
102
103     /**
104      * Checks if an item exists through ArrayAccess.
105      *
106      * This method just forwards the request to the inner iterator
107      *
108      * @param int $offset
109      * @return bool
110      */
111     public function offsetExists($offset) {
112
113         $iterator = $this->getIterator();
114         return $iterator->offsetExists($offset);
115
116     }
117
118     /**
119      * Gets an item through ArrayAccess.
120      *
121      * This method just forwards the request to the inner iterator
122      *
123      * @param int $offset
124      * @return mixed
125      */
126     public function offsetGet($offset) {
127
128         $iterator = $this->getIterator();
129         return $iterator->offsetGet($offset);
130
131     }
132
133     /**
134      * Sets an item through ArrayAccess.
135      *
136      * This method just forwards the request to the inner iterator
137      *
138      * @param int $offset
139      * @param mixed $value
140      * @return void
141      */
142     public function offsetSet($offset,$value) {
143
144         $iterator = $this->getIterator();
145         $iterator->offsetSet($offset,$value);
146
147     }
148
149     /**
150      * Sets an item through ArrayAccess.
151      *
152      * This method just forwards the request to the inner iterator
153      *
154      * @param int $offset
155      * @return void
156      */
157     public function offsetUnset($offset) {
158
159         $iterator = $this->getIterator();
160         $iterator->offsetUnset($offset);
161
162     }
163
164     /* }}} */
165
166 }