*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Ldap / Node / ChildrenIterator.php
bloba392c5c313f9bd7314fe74423470776faea4c731
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Ldap
17 * @subpackage Node
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 $
23 /**
24 * @see Zend_Ldap_Node
26 require_once 'Zend/Ldap/Node.php';
28 /**
29 * Zend_Ldap_Node_ChildrenIterator provides an iterator to a collection of children nodes.
31 * @category Zend
32 * @package Zend_Ldap
33 * @subpackage Node
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
39 /**
40 * An array of Zend_Ldap_Node objects
42 * @var array
44 private $_data;
46 /**
47 * Constructor.
49 * @param array $data
50 * @return void
52 public function __construct(array $data)
54 $this->_data = $data;
57 /**
58 * Returns the number of child nodes.
59 * Implements Countable
61 * @return int
63 public function count()
65 return count($this->_data);
68 /**
69 * Return the current child.
70 * Implements Iterator
72 * @return Zend_Ldap_Node
74 public function current()
76 return current($this->_data);
79 /**
80 * Return the child'd RDN.
81 * Implements Iterator
83 * @return string
85 public function key()
87 return key($this->_data);
90 /**
91 * Move forward to next child.
92 * Implements Iterator
94 public function next()
96 next($this->_data);
99 /**
100 * Rewind the Iterator to the first child.
101 * Implements Iterator
103 public function rewind()
105 reset($this->_data);
109 * Check if there is a current child
110 * after calls to rewind() or next().
111 * Implements Iterator
113 * @return boolean
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.
124 * @return boolean
126 public function hasChildren()
128 if ($this->current() instanceof Zend_Ldap_Node) {
129 return $this->current()->hasChildren();
130 } else {
131 return false;
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();
144 } else {
145 return null;
150 * Returns a child with a given RDN.
151 * Implements ArrayAccess.
153 * @param string $rdn
154 * @return Zend_Ldap_node
156 public function offsetGet($rdn)
158 if ($this->offsetExists($rdn)) {
159 return $this->_data[$rdn];
160 } else {
161 return null;
166 * Checks whether a given rdn exists.
167 * Implements ArrayAccess.
169 * @param string $rdn
170 * @return boolean
172 public function offsetExists($rdn)
174 return (array_key_exists($rdn, $this->_data));
178 * Does nothing.
179 * Implements ArrayAccess.
181 * @param string $name
182 * @return null
184 public function offsetUnset($name) { }
187 * Does nothing.
188 * Implements ArrayAccess.
190 * @param string $name
191 * @param mixed $value
192 * @return null
194 public function offsetSet($name, $value) { }
197 * Get all children as an array
199 * @return array
201 public function toArray()
203 $data = array();
204 foreach ($this as $rdn => $node) {
205 $data[$rdn] = $node;
207 return $data;