source: trunk/library/Zend/Ldap/Node/ChildrenIterator.php @ 5146

Revision 5146, 4.5 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus. Library: adicionando arquivos.

Line 
1<?php
2/**
3 * Zend Framework
4 *
5 * LICENSE
6 *
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.
14 *
15 * @category   Zend
16 * @package    Zend_Ldap
17 * @subpackage Node
18 * @copyright  Copyright (c) 2005-2010 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 20096 2010-01-06 02:05:09Z bkarwin $
21 */
22
23/**
24 * @see Zend_Ldap_Node
25 */
26require_once 'Zend/Ldap/Node.php';
27
28/**
29 * Zend_Ldap_Node_ChildrenIterator provides an iterator to a collection of children nodes.
30 *
31 * @category   Zend
32 * @package    Zend_Ldap
33 * @subpackage Node
34 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
35 * @license    http://framework.zend.com/license/new-bsd     New BSD License
36 */
37class Zend_Ldap_Node_ChildrenIterator implements Iterator, Countable, RecursiveIterator, ArrayAccess
38{
39    /**
40     * An array of Zend_Ldap_Node objects
41     *
42     * @var array
43     */
44    private $_data;
45
46    /**
47     * Constructor.
48     *
49     * @param  array $data
50     * @return void
51     */
52    public function __construct(array $data)
53    {
54        $this->_data = $data;
55    }
56
57    /**
58     * Returns the number of child nodes.
59     * Implements Countable
60     *
61     * @return int
62     */
63    public function count()
64    {
65        return count($this->_data);
66    }
67
68    /**
69     * Return the current child.
70     * Implements Iterator
71     *
72     * @return Zend_Ldap_Node
73     */
74    public function current()
75    {
76        return current($this->_data);
77    }
78
79    /**
80     * Return the child'd RDN.
81     * Implements Iterator
82     *
83     * @return string
84     */
85    public function key()
86    {
87        return key($this->_data);
88    }
89
90    /**
91     * Move forward to next child.
92     * Implements Iterator
93     */
94    public function next()
95    {
96        next($this->_data);
97    }
98
99    /**
100     * Rewind the Iterator to the first child.
101     * Implements Iterator
102     */
103    public function rewind()
104    {
105        reset($this->_data);
106    }
107
108    /**
109     * Check if there is a current child
110     * after calls to rewind() or next().
111     * Implements Iterator
112     *
113     * @return boolean
114     */
115    public function valid()
116    {
117        return (current($this->_data)!==false);
118    }
119
120    /**
121     * Checks if current node has children.
122     * Returns whether the current element has children.
123     *
124     * @return boolean
125     */
126    public function hasChildren()
127    {
128        if ($this->current() instanceof Zend_Ldap_Node) {
129            return $this->current()->hasChildren();
130        } else {
131            return false;
132        }
133    }
134
135    /**
136     * Returns the children for the current node.
137     *
138     * @return Zend_Ldap_Node_ChildrenIterator
139     */
140    public function getChildren()
141    {
142        if ($this->current() instanceof Zend_Ldap_Node) {
143            return $this->current()->getChildren();
144        } else {
145            return null;
146        }
147    }
148
149    /**
150     * Returns a child with a given RDN.
151     * Implements ArrayAccess.
152     *
153     * @param  string $rdn
154     * @return Zend_Ldap_node
155     */
156    public function offsetGet($rdn)
157    {
158        if ($this->offsetExists($rdn)) {
159            return $this->_data[$rdn];
160        } else {
161            return null;
162        }
163    }
164
165    /**
166     * Checks whether a given rdn exists.
167     * Implements ArrayAccess.
168     *
169     * @param  string $rdn
170     * @return boolean
171     */
172    public function offsetExists($rdn)
173    {
174        return (array_key_exists($rdn, $this->_data));
175    }
176
177    /**
178     * Does nothing.
179     * Implements ArrayAccess.
180     *
181     * @param  string $name
182     * @return null
183     */
184    public function offsetUnset($name) { }
185
186    /**
187     * Does nothing.
188     * Implements ArrayAccess.
189     *
190     * @param  string $name
191     * @param  mixed $value
192     * @return null
193     */
194    public function offsetSet($name, $value) { }
195
196    /**
197     * Get all children as an array
198     *
199     * @return array
200     */
201    public function toArray()
202    {
203        $data = array();
204        foreach ($this as $rdn => $node) {
205            $data[$rdn] = $node;
206        }
207        return $data;
208    }
209}
Note: See TracBrowser for help on using the repository browser.