summaryrefslogtreecommitdiff
path: root/ext/spl/spl.php
blob: ec92c8468389018e488adae17537c07d309bc8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php

/** Standard PHP Library
 *
 * (c) Marcus Boerger, 2003
 */

/** Abstract base interface that cannot be implemented alone. Instead it
 * must be implemented by either IteratorAggregate or Iterator. 
 *
 * \note Internal classes that implement this interface can be used in a 
 * foreach construct and do not need to implement IteratorAggregate or
 * Iterator.
 */
interface Traversable {
}

/** Interface to create an external Iterator.
 */ 
interface IteratorAggregate implements Traversable {
	/** Return an Iterator for the implementing object.
	 */
	function getIterator();
}

/** Interface for external iterators or objects that can be iterated 
 * themselves internally.
 */
interface Iterator implements Traversable {
	/** Rewind the Iterator to the first element.
	 */
	function rewind();

	/** Return the current element.
	 */
	function current();

	/** Return the key of the current element.
	 */
	function key();

	/** Move forward to next element.
	 */
	function next();

	/** Check if there is a current element after calls to rewind() or next().
	 */
	function hasMore();
}

/** Interface for recursive traversal to be used with 
 * RecursiveIteratorIterator.
 */
interface RecursiveIterator implements Iterator {
	/** \return whether current element can be iterated itself.
	  */
	function hasChildren();

	/** \return an object that recursively iterates the current element.
	 * This object must implement RecursiveIterator.
	 */
	function getChildren();
}

/** Class for recursive traversal. The objects of this class are created by 
 * instances of RecursiveIterator. Elements of those iterators may be 
 * traversable themselves. If so these sub elements are recursed into.
 */
class RecursiveIteratorIterator implements Iterator {
	/** Construct an instance form a RecursiveIterator.
	 *
	 * \param $iterator inner root iterator
	 * \param $mode one of
	 *            - RIT_LEAVES_ONLY do not return elements that can be recursed.
	 *            - RIT_SELF_FIRST  show elements before their sub elements.
	 *            - RIT_CHILD_FIRST show elements after their sub elements-
	 *
	 * \note If you want to see only those elements which have sub elements then
	 *       use a ParentIterator.
	 */
	function __construct(RecursiveIterator $iterator, $mode);

	/** \return the level of recursion (>=0).
	 */
	function getDepth();

	/** \param $level the level of the sub iterator to return.
	 * \return the current inner sub iterator or the iterator at the 
	 * specified $level.
	 */
	function getSubIterator([$level]);
}

/** \brief An Array wrapper
 *
 * This array wrapper allows to recursively iterate over Arrays and Objects.
 *
 * \see ArrayIterator
 */
class ArrayObject implements IteratorAggregate {

	/** Construct a new array iterator from anything that has a hash table.
	 * That is any Array or Object.
	 *
	 * \param $array the array to use.
	 */
	function __construct($array);

	/** Get the iterator which is a ArrayIterator object connected to this 
	 * object.
	 */
	function getIterator();
}

/** \brief An Array iterator
 *
 * This iterator allows to unset and modify values and keys while iterating
 * over Arrays and Objects.
 *
 * To use this class you must instanciate ArrayObject.
 */
class ArrayIterator implements Iterator {

	/** Construct a new array iterator from anything that has a hash table.
	 * That is any Array or Object.
	 *
	 * \param $array the array to use.
	 */
	private function __construct($array);

	/** \copydoc Iterator::rewind
	 */
	function rewind();

	/** \copydoc Iterator::current
	 */
	function current();

	/** \copydoc Iterator::key
	 */
	function key();

	/** \copydoc Iterator::next
	 */
	function next();

	/** \copydoc Iterator::hasMore
	 */
	function hasMore();
}

/** Iterator that wrapps around another iterator and only returns selected
 * elements of the inner iterator.
 */
abstract class FilterIterator implements Iterator {
	/** Construct an instance form a Iterator.
	 *
	 * \param $iterator inner iterator
	 */
	function __construct(Iterator $iterator);

	/** \return whether the current element of the inner iterator should be
	 * used as a current element of this iterator or if it should be skipped.
	 */
	abstract function accept();

	/** \copydoc Iterator::rewind
	 */
	function rewind();

	/** \copydoc Iterator::current
	 */
	function current();

	/** \copydoc Iterator::key
	 */
	function key();

	/** \copydoc Iterator::next
	 */
	function next();

	/** \copydoc Iterator::hasMore
	 */
	function hasMore();
}

/** A recursive iterator that only returns elements that themselves can be 
 * trversed.
 */
class ParentIterator extends FilterIterator implements RecursiveIterator {
	/** Construct an instance form a RecursiveIterator.
	 *
	 * \param $iterator inner iterator
	 */
	function __construct(RecursiveIterator $iterator);

	/** \copydoc RecursiveIterator::hasChildren
	 */
	function hasChildren();

	/** \copydoc RecursiveIterator::getChildren
	 */
	function getChildren();

	/** \copydoc Iterator::rewind
	 */
	function rewind();

	/** \copydoc Iterator::current
	 */
	function current();

	/** \copydoc Iterator::key
	 */
	function key();

	/** \copydoc Iterator::next
	 */
	function next();

	/** \copydoc Iterator::hasMore
	 */
	function hasMore();
}

/** \brief Directory iterator
 */
class DirectoryIterator implements Iterator {

	/** Construct a directory iterator from a path-string.
	 *
	 * \param $path directory to iterate.
	 */
	function __construct($path);

	/** \copydoc Iterator::rewind
	 */
	function rewind();

	/** \copydoc Iterator::current
	 */
	function current();

	/** \copydoc Iterator::next
	 */
	function next();

	/** \copydoc Iterator::hasMore
	 */
	function hasMore();
	
	/** \return The opened path.
	 */
	function getPath();	

	/** \return The current file name.
	 */
	function getFilename();	

	/** \return The current entries path and file name.
	 */
	function getPathname();	

	/** \return Whether the current entry is a directory.
	 */
	function isDir();	

	/** \return Whether the current entry is either '.' or '..'.
	 */
	function isDot();	
}

/** \brief recursive directory iterator
 */
class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator {

	/** \return whether the current is a directory (not '.' or '..').
	 */
	function hasChildren();	

	/** \return a RecursiveDirectoryIterator for the current entry.
	 */
	function getChildren();	
	
}

?>