La clase ParentIterator

(PHP 5 >= 5.1.0)

Introducción

Esta FilterIterator ampliada permite una iteración recursiva usando RecursiveIteratorIterator, que solamente muestra los elementos que tienen hijos.

Sinopsis de la Clase

ParentIterator extends RecursiveFilterIterator implements RecursiveIterator , OuterIterator {
/* Métodos */
public bool accept ( void )
public __construct ( RecursiveIterator $iterator )
public ParentIterator getChildren ( void )
public bool hasChildren ( void )
public void next ( void )
public void rewind ( void )
}

Tabla de contenidos

add a note add a note

User Contributed Notes 1 note

up
2
Anonymous
2 years ago
ParentIterator is just a RecursiveFilterIterator whos accept() method calls the RecursiveFilterIterator->hasChildren() method to filter itself.

Basically, it filters out leaf nodes. For example

This would yield all files and directories
<?php
$rdi
= new RecursiveDirectoryIterator(__DIR__);
$iter = new RecursiveIteratorIterator($rdi, RecursiveIteratorIterator::CHILD_FIRST);
?>

wrapping that in a ParentIterator would filter it down to just directories
<?php
$rdi
= new RecursiveDirectoryIterator(__DIR__);
$iter = new RecursiveIteratorIterator($rdi, RecursiveIteratorIterator::CHILD_FIRST);
$dirsOnly = new ParentIterator($iter);
?>
To Top