Source of file ChildrenIterator.php
Size: 3,790 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Ldap/Node/ChildrenIterator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Ldap\Node; use ArrayAccess; use Countable; use Iterator; use RecursiveIterator; use Zend\Ldap; /** * Zend\Ldap\Node\ChildrenIterator provides an iterator to a collection of children nodes. */ class ChildrenIterator implements Iterator, Countable, RecursiveIterator, ArrayAccess { /** * An array of Zend\Ldap\Node objects * * @var array */ private $data; /** * Constructor. * * @param array $data * @return \Zend\Ldap\Node\ChildrenIterator */ public function __construct(array $data) { $this->data = $data; } /** * Returns the number of child nodes. * Implements Countable * * @return int */ public function count() { return count($this->data); } /** * Return the current child. * Implements Iterator * * @return \Zend\Ldap\Node */ public function current() { return current($this->data); } /** * Return the child'd RDN. * Implements Iterator * * @return string */ public function key() { return key($this->data); } /** * Move forward to next child. * Implements Iterator */ public function next() { next($this->data); } /** * Rewind the Iterator to the first child. * Implements Iterator */ public function rewind() { reset($this->data); } /** * Check if there is a current child * after calls to rewind() or next(). * Implements Iterator * * @return bool */ public function valid() { return (current($this->data) !== false); } /** * Checks if current node has children. * Returns whether the current element has children. * * @return bool */ public function hasChildren() { if ($this->current() instanceof Ldap\Node) { return $this->current()->hasChildren(); } return false; } /** * Returns the children for the current node. * * @return ChildrenIterator */ public function getChildren() { if ($this->current() instanceof Ldap\Node) { return $this->current()->getChildren(); } return null; } /** * Returns a child with a given RDN. * Implements ArrayAccess. * * @param string $rdn * @return array|null */ public function offsetGet($rdn) { if ($this->offsetExists($rdn)) { return $this->data[$rdn]; } return null; } /** * Checks whether a given rdn exists. * Implements ArrayAccess. * * @param string $rdn * @return bool */ public function offsetExists($rdn) { return (array_key_exists($rdn, $this->data)); } /** * Does nothing. * Implements ArrayAccess. * * @param $name */ public function offsetUnset($name) { } /** * Does nothing. * Implements ArrayAccess. * * @param string $name * @param $value */ public function offsetSet($name, $value) { } /** * Get all children as an array * * @return array */ public function toArray() { $data = array(); foreach ($this as $rdn => $node) { $data[$rdn] = $node; } return $data; } } |