## Apache Zeta Components Manual :: Docs For Class ezcTreeNodeListIterator

### Tree::ezcTreeNodeListIterator

### Class ezcTreeNodeListIterator

ezcTreeNodeListIterator implements an iterator over an ezcTreeNodeList.

The iterator is instantiated with both an implementation of an ezcTree and an ezcTreeNodeList object. It can be used to iterate over all the nodes in a list.

Example:

1. <?php
2. // fetch all the nodes in a subtree as an ezcNodeList
3. $nodeList=$tree->fetchSubtree('pan');
4. foreach(new ezcTreeNodeListIterator ($tree,$nodeList)as$nodeId=>$data)
5. {
6. // do something with the node ID and data - data is fetched on
7. // demand
8. }
9. ?>

Data for the nodes in the node lists is fetched on demand, unless the "prefetch" argument is set to true. In that case the iterator will fetch the data when the iterator is instantiated. This reduces the number of queries made for database and persistent object based data stores, but increases memory usage.

Example:

1. <?php
2. // fetch all the nodes in a subtree as an ezcNodeList
3. $nodeList=$tree->fetchSubtree('Uranus');
4. // instantiate an iterator with pre-fetching enabled
5. foreach(new ezcTreeNodeListIterator ($tree,$nodeList,true)as$nodeId=>$data)
6. {
7. // do something with the node ID and data - data is fetched when
8. // the iterator is instatiated.
9. }
10. ?>

Source for this file: /Tree/src/tree_node_list_iterator.php

### Implements interfaces:

- Iterator (internal interface)

Version: | //autogentag//

### Method Summary

public ezcTreeNodeListIterator | `__construct( $tree , $nodeList , [ $prefetch = false] )` Constructs a new ezcTreeNodeListIterator object over $nodeList.
public mixed | `current( )` Returns the data belonging to the current node, and fetches the data in case on-demand fetching is required.
public string | `key( )` Returns the node ID of the current node.
public void | `next( )` Advances the internal pointer to the next node in the nodelist.
public void | `rewind( )` Rewinds the internal pointer back to the start of the nodelist.
public bool | `valid( )` Returns whether the internal pointer is still valid.

### Methods

#### __construct

ezcTreeNodeListIterator __construct( ezcTree $tree , ezcTreeNodeList $nodeList , [bool $prefetch = false] )

Constructs a new ezcTreeNodeListIterator object over $nodeList.

The $tree argument is used so that data can be fetched on-demand.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$tree` | ezcTree |
`$nodeList` | ezcTreeNodeList |
`$prefetch` | bool |

#### current

mixed current( )

Returns the data belonging to the current node, and fetches the data in case on-demand fetching is required.

##### Implementation of:

Method | Description
--- | ---
`Iterator::current` |

#### key

string key( )

Returns the node ID of the current node.

##### Implementation of:

Method | Description
--- | ---
`Iterator::key` |

#### next

void next( )

Advances the internal pointer to the next node in the nodelist.

##### Implementation of:

Method | Description
--- | ---
`Iterator::next` |

#### rewind

void rewind( )

Rewinds the internal pointer back to the start of the nodelist.

##### Implementation of:

Method | Description
--- | ---
`Iterator::rewind` |

#### valid

bool valid( )

Returns whether the internal pointer is still valid.

It returns false when the end of list has been reached.

##### Implementation of:

Method | Description
--- | ---
`Iterator::valid` |

Documentation generated by phpDocumentor 1.4.3