File indexing completed on 2025-01-26 05:29:38
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Ldap 0017 * @subpackage Node 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Ldap_Node 0025 */ 0026 // require_once 'Zend/Ldap/Node.php'; 0027 0028 /** 0029 * Zend_Ldap_Node_ChildrenIterator provides an iterator to a collection of children nodes. 0030 * 0031 * @category Zend 0032 * @package Zend_Ldap 0033 * @subpackage Node 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Ldap_Node_ChildrenIterator implements Iterator, Countable, RecursiveIterator, ArrayAccess 0038 { 0039 /** 0040 * An array of Zend_Ldap_Node objects 0041 * 0042 * @var array 0043 */ 0044 private $_data; 0045 0046 /** 0047 * Constructor. 0048 * 0049 * @param array $data 0050 * @return void 0051 */ 0052 public function __construct(array $data) 0053 { 0054 $this->_data = $data; 0055 } 0056 0057 /** 0058 * Returns the number of child nodes. 0059 * Implements Countable 0060 * 0061 * @return int 0062 */ 0063 public function count() 0064 { 0065 return count($this->_data); 0066 } 0067 0068 /** 0069 * Return the current child. 0070 * Implements Iterator 0071 * 0072 * @return Zend_Ldap_Node 0073 */ 0074 public function current() 0075 { 0076 return current($this->_data); 0077 } 0078 0079 /** 0080 * Return the child'd RDN. 0081 * Implements Iterator 0082 * 0083 * @return string 0084 */ 0085 public function key() 0086 { 0087 return key($this->_data); 0088 } 0089 0090 /** 0091 * Move forward to next child. 0092 * Implements Iterator 0093 */ 0094 public function next() 0095 { 0096 next($this->_data); 0097 } 0098 0099 /** 0100 * Rewind the Iterator to the first child. 0101 * Implements Iterator 0102 */ 0103 public function rewind() 0104 { 0105 reset($this->_data); 0106 } 0107 0108 /** 0109 * Check if there is a current child 0110 * after calls to rewind() or next(). 0111 * Implements Iterator 0112 * 0113 * @return boolean 0114 */ 0115 public function valid() 0116 { 0117 return (current($this->_data)!==false); 0118 } 0119 0120 /** 0121 * Checks if current node has children. 0122 * Returns whether the current element has children. 0123 * 0124 * @return boolean 0125 */ 0126 public function hasChildren() 0127 { 0128 if ($this->current() instanceof Zend_Ldap_Node) { 0129 return $this->current()->hasChildren(); 0130 } else { 0131 return false; 0132 } 0133 } 0134 0135 /** 0136 * Returns the children for the current node. 0137 * 0138 * @return Zend_Ldap_Node_ChildrenIterator 0139 */ 0140 public function getChildren() 0141 { 0142 if ($this->current() instanceof Zend_Ldap_Node) { 0143 return $this->current()->getChildren(); 0144 } else { 0145 return null; 0146 } 0147 } 0148 0149 /** 0150 * Returns a child with a given RDN. 0151 * Implements ArrayAccess. 0152 * 0153 * @param string $rdn 0154 * @return Zend_Ldap_node 0155 */ 0156 public function offsetGet($rdn) 0157 { 0158 if ($this->offsetExists($rdn)) { 0159 return $this->_data[$rdn]; 0160 } else { 0161 return null; 0162 } 0163 } 0164 0165 /** 0166 * Checks whether a given rdn exists. 0167 * Implements ArrayAccess. 0168 * 0169 * @param string $rdn 0170 * @return boolean 0171 */ 0172 public function offsetExists($rdn) 0173 { 0174 return (array_key_exists($rdn, $this->_data)); 0175 } 0176 0177 /** 0178 * Does nothing. 0179 * Implements ArrayAccess. 0180 * 0181 * @param string $name 0182 * @return null 0183 */ 0184 public function offsetUnset($name) { } 0185 0186 /** 0187 * Does nothing. 0188 * Implements ArrayAccess. 0189 * 0190 * @param string $name 0191 * @param mixed $value 0192 * @return null 0193 */ 0194 public function offsetSet($name, $value) { } 0195 0196 /** 0197 * Get all children as an array 0198 * 0199 * @return array 0200 */ 0201 public function toArray() 0202 { 0203 $data = array(); 0204 foreach ($this as $rdn => $node) { 0205 $data[$rdn] = $node; 0206 } 0207 return $data; 0208 } 0209 }