7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
18 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: ChildrenIterator.php 13152 2008-12-11 11:28:02Z sgehrig $
26 require_once 'Zend/Ldap/Node.php';
29 * Zend_Ldap_Node_ChildrenIterator provides an iterator to a collection of children nodes.
34 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
35 * @license http://framework.zend.com/license/new-bsd New BSD License
37 class Zend_Ldap_Node_ChildrenIterator
implements Iterator
, Countable
, RecursiveIterator
, ArrayAccess
40 * An array of Zend_Ldap_Node objects
52 public function __construct(array $data)
58 * Returns the number of child nodes.
59 * Implements Countable
63 public function count()
65 return count($this->_data
);
69 * Return the current child.
72 * @return Zend_Ldap_Node
74 public function current()
76 return current($this->_data
);
80 * Return the child'd RDN.
87 return key($this->_data
);
91 * Move forward to next child.
94 public function next()
100 * Rewind the Iterator to the first child.
101 * Implements Iterator
103 public function rewind()
109 * Check if there is a current child
110 * after calls to rewind() or next().
111 * Implements Iterator
115 public function valid()
117 return (current($this->_data
)!==false);
121 * Checks if current node has children.
122 * Returns whether the current element has children.
126 public function hasChildren()
128 if ($this->current() instanceof Zend_Ldap_Node
) {
129 return $this->current()->hasChildren();
136 * Returns the children for the current node.
138 * @return Zend_Ldap_Node_ChildrenIterator
140 public function getChildren()
142 if ($this->current() instanceof Zend_Ldap_Node
) {
143 return $this->current()->getChildren();
150 * Returns a child with a given RDN.
151 * Implements ArrayAccess.
154 * @return Zend_Ldap_node
156 public function offsetGet($rdn)
158 if ($this->offsetExists($rdn)) {
159 return $this->_data
[$rdn];
166 * Checks whether a given rdn exists.
167 * Implements ArrayAccess.
172 public function offsetExists($rdn)
174 return (array_key_exists($rdn, $this->_data
));
179 * Implements ArrayAccess.
181 * @param string $name
184 public function offsetUnset($name) { }
188 * Implements ArrayAccess.
190 * @param string $name
191 * @param mixed $value
194 public function offsetSet($name, $value) { }
197 * Get all children as an array
201 public function toArray()
204 foreach ($this as $rdn => $node) {