]> 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     /* {{{ IteratorAggregator interface */
36
37     /**
38      * Returns the iterator for this object
39      *
40      * @return Sabre_VObject_ElementList
41      */
42     public function getIterator() {
43
44         if (!is_null($this->iterator))
45             return $this->iterator;
46
47         return new Sabre_VObject_ElementList(array($this));
48
49     }
50
51     /**
52      * Sets the overridden iterator
53      *
54      * Note that this is not actually part of the iterator interface
55      *
56      * @param Sabre_VObject_ElementList $iterator
57      * @return void
58      */
59     public function setIterator(Sabre_VObject_ElementList $iterator) {
60
61         $this->iterator = $iterator;
62
63     }
64
65     /* }}} */
66
67     /* {{{ Countable interface */
68
69     /**
70      * Returns the number of elements
71      *
72      * @return int
73      */
74     public function count() {
75
76         $it = $this->getIterator();
77         return $it->count();
78
79     }
80
81     /* }}} */
82
83     /* {{{ ArrayAccess Interface */
84
85
86     /**
87      * Checks if an item exists through ArrayAccess.
88      *
89      * This method just forwards the request to the inner iterator
90      *
91      * @param int $offset
92      * @return bool
93      */
94     public function offsetExists($offset) {
95
96         $iterator = $this->getIterator();
97         return $iterator->offsetExists($offset);
98
99     }
100
101     /**
102      * Gets an item through ArrayAccess.
103      *
104      * This method just forwards the request to the inner iterator
105      *
106      * @param int $offset
107      * @return mixed
108      */
109     public function offsetGet($offset) {
110
111         $iterator = $this->getIterator();
112         return $iterator->offsetGet($offset);
113
114     }
115
116     /**
117      * Sets an item through ArrayAccess.
118      *
119      * This method just forwards the request to the inner iterator
120      *
121      * @param int $offset
122      * @param mixed $value
123      * @return void
124      */
125     public function offsetSet($offset,$value) {
126
127         $iterator = $this->getIterator();
128         $iterator->offsetSet($offset,$value);
129
130     }
131
132     /**
133      * Sets an item through ArrayAccess.
134      *
135      * This method just forwards the request to the inner iterator
136      *
137      * @param int $offset
138      * @return void
139      */
140     public function offsetUnset($offset) {
141
142         $iterator = $this->getIterator();
143         $iterator->offsetUnset($offset);
144
145     }
146
147     /* }}} */
148
149 }