3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Ldap\Node
;
15 use RecursiveIterator
;
19 * Zend\Ldap\Node\ChildrenIterator provides an iterator to a collection of children nodes.
21 class ChildrenIterator
implements Iterator
, Countable
, RecursiveIterator
, ArrayAccess
24 * An array of Zend\Ldap\Node objects
34 * @return \Zend\Ldap\Node\ChildrenIterator
36 public function __construct(array $data)
42 * Returns the number of child nodes.
43 * Implements Countable
47 public function count()
49 return count($this->data
);
53 * Return the current child.
56 * @return \Zend\Ldap\Node
58 public function current()
60 return current($this->data
);
64 * Return the child'd RDN.
71 return key($this->data
);
75 * Move forward to next child.
78 public function next()
84 * Rewind the Iterator to the first child.
87 public function rewind()
93 * Check if there is a current child
94 * after calls to rewind() or next().
99 public function valid()
101 return (current($this->data
) !== false);
105 * Checks if current node has children.
106 * Returns whether the current element has children.
110 public function hasChildren()
112 if ($this->current() instanceof Ldap\Node
) {
113 return $this->current()->hasChildren();
120 * Returns the children for the current node.
122 * @return ChildrenIterator
124 public function getChildren()
126 if ($this->current() instanceof Ldap\Node
) {
127 return $this->current()->getChildren();
134 * Returns a child with a given RDN.
135 * Implements ArrayAccess.
140 public function offsetGet($rdn)
142 if ($this->offsetExists($rdn)) {
143 return $this->data
[$rdn];
150 * Checks whether a given rdn exists.
151 * Implements ArrayAccess.
156 public function offsetExists($rdn)
158 return (array_key_exists($rdn, $this->data
));
163 * Implements ArrayAccess.
167 public function offsetUnset($name)
173 * Implements ArrayAccess.
175 * @param string $name
178 public function offsetSet($name, $value)
183 * Get all children as an array
187 public function toArray()
190 foreach ($this as $rdn => $node) {