Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Ldap / Node / ChildrenIterator.php
blobda67dbccb39c3c27f7b1c83703d59b1c7b45ff33
1 <?php
2 /**
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
8 */
10 namespace Zend\Ldap\Node;
12 use ArrayAccess;
13 use Countable;
14 use Iterator;
15 use RecursiveIterator;
16 use Zend\Ldap;
18 /**
19 * Zend\Ldap\Node\ChildrenIterator provides an iterator to a collection of children nodes.
21 class ChildrenIterator implements Iterator, Countable, RecursiveIterator, ArrayAccess
23 /**
24 * An array of Zend\Ldap\Node objects
26 * @var array
28 private $data;
30 /**
31 * Constructor.
33 * @param array $data
34 * @return \Zend\Ldap\Node\ChildrenIterator
36 public function __construct(array $data)
38 $this->data = $data;
41 /**
42 * Returns the number of child nodes.
43 * Implements Countable
45 * @return int
47 public function count()
49 return count($this->data);
52 /**
53 * Return the current child.
54 * Implements Iterator
56 * @return \Zend\Ldap\Node
58 public function current()
60 return current($this->data);
63 /**
64 * Return the child'd RDN.
65 * Implements Iterator
67 * @return string
69 public function key()
71 return key($this->data);
74 /**
75 * Move forward to next child.
76 * Implements Iterator
78 public function next()
80 next($this->data);
83 /**
84 * Rewind the Iterator to the first child.
85 * Implements Iterator
87 public function rewind()
89 reset($this->data);
92 /**
93 * Check if there is a current child
94 * after calls to rewind() or next().
95 * Implements Iterator
97 * @return bool
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.
108 * @return bool
110 public function hasChildren()
112 if ($this->current() instanceof Ldap\Node) {
113 return $this->current()->hasChildren();
116 return false;
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();
130 return null;
134 * Returns a child with a given RDN.
135 * Implements ArrayAccess.
137 * @param string $rdn
138 * @return array|null
140 public function offsetGet($rdn)
142 if ($this->offsetExists($rdn)) {
143 return $this->data[$rdn];
146 return null;
150 * Checks whether a given rdn exists.
151 * Implements ArrayAccess.
153 * @param string $rdn
154 * @return bool
156 public function offsetExists($rdn)
158 return (array_key_exists($rdn, $this->data));
162 * Does nothing.
163 * Implements ArrayAccess.
165 * @param $name
167 public function offsetUnset($name)
172 * Does nothing.
173 * Implements ArrayAccess.
175 * @param string $name
176 * @param $value
178 public function offsetSet($name, $value)
183 * Get all children as an array
185 * @return array
187 public function toArray()
189 $data = array();
190 foreach ($this as $rdn => $node) {
191 $data[$rdn] = $node;
193 return $data;