Annotation of embedaddon/php/ext/spl/tests/iterator_002.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: SPL: Iterator using getInnerIterator
! 3: --FILE--
! 4: <?php
! 5:
! 6: class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator
! 7: {
! 8: function hasChildren()
! 9: {
! 10: return is_array($this->current());
! 11: }
! 12:
! 13: function getChildren()
! 14: {
! 15: return new RecursiceArrayIterator($this->current());
! 16: }
! 17: }
! 18:
! 19: class CrashIterator extends FilterIterator implements RecursiveIterator
! 20: {
! 21: function accept()
! 22: {
! 23: return true;
! 24: }
! 25:
! 26: function hasChildren()
! 27: {
! 28: return $this->getInnerIterator()->hasChildren();
! 29: }
! 30:
! 31: function getChildren()
! 32: {
! 33: return new RecursiceArrayIterator($this->getInnerIterator()->current());
! 34: }
! 35: }
! 36:
! 37: $array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);
! 38:
! 39: $dir = new RecursiveIteratorIterator(new CrashIterator(new RecursiceArrayIterator($array)), RecursiveIteratorIterator::LEAVES_ONLY);
! 40:
! 41: foreach ($dir as $file) {
! 42: print "$file\n";
! 43: }
! 44:
! 45: ?>
! 46: ===DONE===
! 47: <?php exit(0); ?>
! 48: --EXPECT--
! 49: 1
! 50: 21
! 51: 221
! 52: 222
! 53: 231
! 54: 3
! 55: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>