La classe ParentIterator

(PHP 5 >= 5.1.0, PHP 7)

Introduction

Ce sous-type de FilterIterator permet la récursivité au moyen de RecursiveIteratorIterator et il ne montre alors que les éléments ayant des enfants.

Synopsis de la classe

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

Sommaire

add a note add a note

User Contributed Notes 1 note

up
4
Anonymous
7 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