1 : <?php
2 : /**
3 : * Iterator for children of a directory container.
4 : *
5 : * @package bovigo_vfs
6 : * @version $Id: vfsStreamContainerIterator.php 132 2009-07-13 19:13:25Z google@frankkleine.de $
7 : */
8 : /**
9 : * Iterator for children of a directory container.
10 : *
11 : * @package bovigo_vfs
12 : */
13 : class vfsStreamContainerIterator implements Iterator
14 : {
15 : /**
16 : * list of children from container to iterate over
17 : *
18 : * @var array<vfsStreamContent>
19 : */
20 : protected $children = array();
21 :
22 : /**
23 : * constructor
24 : *
25 : * @param array<vfsStreamContent> $children
26 : */
27 : public function __construct(array $children)
28 : {
29 6 : $this->children = $children;
30 6 : reset($this->children);
31 6 : }
32 :
33 : /**
34 : * resets children pointer
35 : */
36 : public function rewind()
37 : {
38 4 : reset($this->children);
39 4 : }
40 :
41 : /**
42 : * returns the current child
43 : *
44 : * @return vfsStreamContent
45 : */
46 : public function current()
47 : {
48 6 : $child = current($this->children);
49 6 : if (false === $child) {
50 5 : return null;
51 : }
52 :
53 6 : return $child;
54 : }
55 :
56 : /**
57 : * returns the name of the current child
58 : *
59 : * @return string
60 : */
61 : public function key()
62 : {
63 1 : $child = current($this->children);
64 1 : if (false === $child) {
65 1 : return null;
66 : }
67 :
68 1 : return $child->getName();
69 : }
70 :
71 : /**
72 : * iterates to next child
73 : */
74 : public function next()
75 : {
76 6 : next($this->children);
77 6 : }
78 :
79 : /**
80 : * checks if the current value is valid
81 : *
82 : * @return bool
83 : */
84 : public function valid()
85 : {
86 1 : return (false !== current($this->children));
87 : }
88 : }
|