Annotation of embedaddon/php/ext/spl/tests/iterator_021.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: SPL: RecursiveIteratorIterator and hasChildren
                      3: --FILE--
                      4: <?php
                      5: 
                      6: class MyRecursiveArrayIterator extends RecursiveArrayIterator
                      7: {
                      8:        function valid()
                      9:        {
                     10:                if (!parent::valid())
                     11:                {
                     12:                        echo __METHOD__ . " = false\n";
                     13:                        return false;
                     14:                }
                     15:                else
                     16:                {
                     17:                        return true;
                     18:                }
                     19:        }
                     20: 
                     21:        function getChildren()
                     22:        {
                     23:                echo __METHOD__ . "\n";
                     24:                return parent::getChildren();
                     25:        }
                     26: }
                     27: 
                     28: class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator
                     29: {
                     30:        private $max_depth;
                     31:        private $over = 0;
                     32:        private $skip = false;
                     33: 
                     34:        function __construct($it, $max_depth)
                     35:        {
                     36:                $this->max_depth = $max_depth;
                     37:                parent::__construct($it);
                     38:        }
                     39: 
                     40:        function rewind()
                     41:        {
                     42:                echo __METHOD__ . "\n";
                     43:                $this->skip = false;
                     44:                parent::rewind();
                     45:        }
                     46: 
                     47:        function valid()
                     48:        {
                     49:                echo __METHOD__ . "\n";
                     50:                if ($this->skip)
                     51:                {
                     52:                        $this->skip = false;
                     53:                        $this->next();
                     54:                }
                     55:                return parent::valid();
                     56:        }
                     57: 
                     58:        function current()
                     59:        {
                     60:                echo __METHOD__ . "\n";
                     61:                return parent::current();
                     62:        }
                     63: 
                     64:        function key()
                     65:        {
                     66:                echo __METHOD__ . "\n";
                     67:                return parent::key();
                     68:        }
                     69: 
                     70:        function next()
                     71:        {
                     72:                echo __METHOD__ . "\n";
                     73:                parent::next();
                     74:        }
                     75: 
                     76:        function callHasChildren()
                     77:        {
                     78:                $this->skip = false;
                     79:                $has = parent::callHasChildren();
                     80:                $res = $this->getDepth() < $this->max_depth && $has;
                     81:                echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n";
                     82:                if ($has && !$res)
                     83:                {
                     84:                        $this->over++;
                     85:                        if ($this->over == 2) {
                     86:                                $this->skip = true;
                     87:                        }
                     88:                }
                     89:                return $res;
                     90:        }
                     91: 
                     92:        function beginChildren()
                     93:        {
                     94:                echo __METHOD__ . "(".$this->getDepth().")\n";
                     95:        }
                     96: 
                     97:        function endChildren()
                     98:        {
                     99:                echo __METHOD__ . "(".$this->getDepth().")\n";
                    100:        }
                    101: }
                    102: 
                    103: foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v)
                    104: {
                    105:        if (is_array($v)) $v = join('',$v);
                    106:        echo "$k=>$v\n";
                    107: }
                    108: ?>
                    109: ===DONE===
                    110: <?php exit(0); ?>
                    111: --EXPECT--
                    112: RecursiveArrayIteratorIterator::rewind
                    113: RecursiveArrayIteratorIterator::callHasChildren(0) = no/no
                    114: RecursiveArrayIteratorIterator::valid
                    115: RecursiveArrayIteratorIterator::current
                    116: RecursiveArrayIteratorIterator::key
                    117: 0=>a
                    118: RecursiveArrayIteratorIterator::next
                    119: RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes
                    120: MyRecursiveArrayIterator::getChildren
                    121: RecursiveArrayIteratorIterator::beginChildren(1)
                    122: RecursiveArrayIteratorIterator::callHasChildren(1) = no/no
                    123: RecursiveArrayIteratorIterator::valid
                    124: RecursiveArrayIteratorIterator::current
                    125: RecursiveArrayIteratorIterator::key
                    126: 0=>ba
                    127: RecursiveArrayIteratorIterator::next
                    128: RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes
                    129: MyRecursiveArrayIterator::getChildren
                    130: RecursiveArrayIteratorIterator::beginChildren(2)
                    131: RecursiveArrayIteratorIterator::callHasChildren(2) = no/no
                    132: RecursiveArrayIteratorIterator::valid
                    133: RecursiveArrayIteratorIterator::current
                    134: RecursiveArrayIteratorIterator::key
                    135: 0=>bba
                    136: RecursiveArrayIteratorIterator::next
                    137: RecursiveArrayIteratorIterator::callHasChildren(2) = no/no
                    138: RecursiveArrayIteratorIterator::valid
                    139: RecursiveArrayIteratorIterator::current
                    140: RecursiveArrayIteratorIterator::key
                    141: 1=>bbb
                    142: RecursiveArrayIteratorIterator::next
                    143: MyRecursiveArrayIterator::valid = false
                    144: RecursiveArrayIteratorIterator::endChildren(2)
                    145: RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes
                    146: MyRecursiveArrayIterator::getChildren
                    147: RecursiveArrayIteratorIterator::beginChildren(2)
                    148: RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes
                    149: RecursiveArrayIteratorIterator::valid
                    150: RecursiveArrayIteratorIterator::current
                    151: RecursiveArrayIteratorIterator::key
                    152: 0=>bcaa
                    153: RecursiveArrayIteratorIterator::next
                    154: RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes
                    155: RecursiveArrayIteratorIterator::valid
                    156: RecursiveArrayIteratorIterator::next
                    157: MyRecursiveArrayIterator::valid = false
                    158: RecursiveArrayIteratorIterator::endChildren(2)
                    159: MyRecursiveArrayIterator::valid = false
                    160: RecursiveArrayIteratorIterator::endChildren(1)
                    161: RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes
                    162: MyRecursiveArrayIterator::getChildren
                    163: RecursiveArrayIteratorIterator::beginChildren(1)
                    164: RecursiveArrayIteratorIterator::callHasChildren(1) = no/no
                    165: RecursiveArrayIteratorIterator::current
                    166: RecursiveArrayIteratorIterator::key
                    167: 0=>ca
                    168: RecursiveArrayIteratorIterator::next
                    169: MyRecursiveArrayIterator::valid = false
                    170: RecursiveArrayIteratorIterator::endChildren(1)
                    171: RecursiveArrayIteratorIterator::callHasChildren(0) = no/no
                    172: RecursiveArrayIteratorIterator::valid
                    173: RecursiveArrayIteratorIterator::current
                    174: RecursiveArrayIteratorIterator::key
                    175: 3=>d
                    176: RecursiveArrayIteratorIterator::next
                    177: MyRecursiveArrayIterator::valid = false
                    178: RecursiveArrayIteratorIterator::valid
                    179: MyRecursiveArrayIterator::valid = false
                    180: ===DONE===

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>