From 9ce7792d8de2eff79b6928ebe8238a6bd63f748b Mon Sep 17 00:00:00 2001 From: Paul Tarjan Date: Mon, 22 Jul 2013 23:04:30 -0700 Subject: [PATCH] implement RecursiveArrayIterator I went through all the tests that mentioned this and looked at them. All of them don't pass because of other missing SPL problems not related to this class (and this class is simple so I wouldn't assume them to blame to it). Closes #766 --- hphp/NEWS | 1 + hphp/system/php.txt | 4 +- .../spl/iterators/RecursiveArrayIterator.php | 54 +++++++++++++++++++ .../iterators/RecursiveIteratorIterator.php | 6 +-- .../zend/{good => bad}/ext-spl/bug54281.php | 0 .../ext-spl/bug54281.php.expectf | 0 .../zend/{bad => good}/ext-spl/array_009.php | 0 .../ext-spl/array_009.php.expectf | 0 .../zend/{bad => good}/ext-spl/array_009a.php | 0 .../ext-spl/array_009a.php.expectf | 0 .../zend/{bad => good}/ext-spl/bug31926.php | 0 .../ext-spl/bug31926.php.expectf | 0 .../zend/{bad => good}/ext-spl/bug44615.php | 0 .../ext-spl/bug44615.php.expectf | 0 .../zend/{bad => good}/ext-spl/bug46115.php | 0 .../ext-spl/bug46115.php.expectf | 0 .../zend/{bad => good}/ext-spl/bug62262.php | 0 .../ext-spl/bug62262.php.expectf | 0 .../ext-spl/spl_iterator_apply_error_001.php | 0 .../spl_iterator_apply_error_001.php.expectf | 0 ...l_recursive_iterator_iterator_key_case.php | 0 ...ive_iterator_iterator_key_case.php.expectf | 0 .../test/zend/{bad => good}/zend/bug60138.php | 0 .../{bad => good}/zend/bug60138.php.expectf | 0 24 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 hphp/system/php/spl/iterators/RecursiveArrayIterator.php rename hphp/test/zend/{good => bad}/ext-spl/bug54281.php (100%) rename hphp/test/zend/{good => bad}/ext-spl/bug54281.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/array_009.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/array_009.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/array_009a.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/array_009a.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug31926.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug31926.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug44615.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug44615.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug46115.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug46115.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug62262.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/bug62262.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/spl_iterator_apply_error_001.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/spl_iterator_apply_error_001.php.expectf (100%) rename hphp/test/zend/{bad => good}/ext-spl/spl_recursive_iterator_iterator_key_case.php (100%) rename hphp/test/zend/{bad => good}/ext-spl/spl_recursive_iterator_iterator_key_case.php.expectf (100%) rename hphp/test/zend/{bad => good}/zend/bug60138.php (100%) rename hphp/test/zend/{bad => good}/zend/bug60138.php.expectf (100%) diff --git a/hphp/NEWS b/hphp/NEWS index 39a35ee25..2164f485a 100644 --- a/hphp/NEWS +++ b/hphp/NEWS @@ -1,5 +1,6 @@ "Tamale" 7/22/2013 + - Implement RecursiveArrayIterator - Optimize vector-shaped Arrays (arrays with keys in range 0..size-1) - Enable HHBC by default in debug builds - Implement SplObjectStorage::getInfo() diff --git a/hphp/system/php.txt b/hphp/system/php.txt index e035219e2..7f3a9a0bc 100644 --- a/hphp/system/php.txt +++ b/hphp/system/php.txt @@ -36,6 +36,9 @@ hphp/system/php/spl/iterators/IteratorIterator.php hphp/system/php/spl/iterators/FilterIterator.php hphp/system/php/spl/iterators/RecursiveFilterIterator.php +hphp/system/php/spl/iterators/ArrayIterator.php +hphp/system/php/spl/iterators/RecursiveArrayIterator.php + hphp/system/php/filter/filter_has_var.php hphp/system/php/filter/filter_input.php hphp/system/php/filter/filter_var_array.php @@ -67,7 +70,6 @@ hphp/system/php/spl/datastructures/SplFixedArray.php hphp/system/php/spl/datastructures/SplObjectStorage.php hphp/system/php/spl/datastructures/SplPriorityQueue.php hphp/system/php/spl/iterators/AppendIterator.php -hphp/system/php/spl/iterators/ArrayIterator.php hphp/system/php/spl/iterators/EmptyIterator.php hphp/system/php/spl/iterators/InfiniteIterator.php hphp/system/php/spl/iterators/LimitIterator.php diff --git a/hphp/system/php/spl/iterators/RecursiveArrayIterator.php b/hphp/system/php/spl/iterators/RecursiveArrayIterator.php new file mode 100644 index 000000000..61b1141a6 --- /dev/null +++ b/hphp/system/php/spl/iterators/RecursiveArrayIterator.php @@ -0,0 +1,54 @@ +hasChildren() ? $this->current() : null, + $this->getFlags() + ); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/recursivearrayiterator.haschildren.php ) + * + * Returns whether current entry is an array or an object for which an + * iterator can be obtained via RecursiveArrayIterator::getChildren(). + * + * @return mixed Returns TRUE if the current entry is an array or an + * object, otherwise FALSE is returned. + */ + public function hasChildren() { + return + is_array($this->current()) || + (is_object($this->current()) && + ($this->getFlags() & self::CHILD_ARRAYS_ONLY) == 0); + } + +} diff --git a/hphp/system/php/spl/iterators/RecursiveIteratorIterator.php b/hphp/system/php/spl/iterators/RecursiveIteratorIterator.php index 6a9807071..9df145d6b 100644 --- a/hphp/system/php/spl/iterators/RecursiveIteratorIterator.php +++ b/hphp/system/php/spl/iterators/RecursiveIteratorIterator.php @@ -66,9 +66,9 @@ class RecursiveIteratorIterator implements OuterIterator, Traversable { */ public function getInnerIterator() { $it = $this->iterators[count($this->iterators)-1][0]; - if (!$it instanceof RecursiveDirectoryIterator) { + if (!$it instanceof RecursiveIterator) { throw new Exception( - "RecursiveIteratorIterator only supports RecursiveDirectoryIterator" + "inner iterator must implement RecursiveIterator" ); } return $it; @@ -200,7 +200,7 @@ class RecursiveIteratorIterator implements OuterIterator, Traversable { $it = $this->getInnerIterator(); if ($it->valid() && - $it->isDir() && + $it->hasChildren() && ($this->mode == self::LEAVES_ONLY || ($this->mode == self::CHILD_FIRST && $this->getInnerIteratorFlag() == 0))) { diff --git a/hphp/test/zend/good/ext-spl/bug54281.php b/hphp/test/zend/bad/ext-spl/bug54281.php similarity index 100% rename from hphp/test/zend/good/ext-spl/bug54281.php rename to hphp/test/zend/bad/ext-spl/bug54281.php diff --git a/hphp/test/zend/good/ext-spl/bug54281.php.expectf b/hphp/test/zend/bad/ext-spl/bug54281.php.expectf similarity index 100% rename from hphp/test/zend/good/ext-spl/bug54281.php.expectf rename to hphp/test/zend/bad/ext-spl/bug54281.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/array_009.php b/hphp/test/zend/good/ext-spl/array_009.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/array_009.php rename to hphp/test/zend/good/ext-spl/array_009.php diff --git a/hphp/test/zend/bad/ext-spl/array_009.php.expectf b/hphp/test/zend/good/ext-spl/array_009.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/array_009.php.expectf rename to hphp/test/zend/good/ext-spl/array_009.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/array_009a.php b/hphp/test/zend/good/ext-spl/array_009a.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/array_009a.php rename to hphp/test/zend/good/ext-spl/array_009a.php diff --git a/hphp/test/zend/bad/ext-spl/array_009a.php.expectf b/hphp/test/zend/good/ext-spl/array_009a.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/array_009a.php.expectf rename to hphp/test/zend/good/ext-spl/array_009a.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/bug31926.php b/hphp/test/zend/good/ext-spl/bug31926.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug31926.php rename to hphp/test/zend/good/ext-spl/bug31926.php diff --git a/hphp/test/zend/bad/ext-spl/bug31926.php.expectf b/hphp/test/zend/good/ext-spl/bug31926.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug31926.php.expectf rename to hphp/test/zend/good/ext-spl/bug31926.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/bug44615.php b/hphp/test/zend/good/ext-spl/bug44615.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug44615.php rename to hphp/test/zend/good/ext-spl/bug44615.php diff --git a/hphp/test/zend/bad/ext-spl/bug44615.php.expectf b/hphp/test/zend/good/ext-spl/bug44615.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug44615.php.expectf rename to hphp/test/zend/good/ext-spl/bug44615.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/bug46115.php b/hphp/test/zend/good/ext-spl/bug46115.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug46115.php rename to hphp/test/zend/good/ext-spl/bug46115.php diff --git a/hphp/test/zend/bad/ext-spl/bug46115.php.expectf b/hphp/test/zend/good/ext-spl/bug46115.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug46115.php.expectf rename to hphp/test/zend/good/ext-spl/bug46115.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/bug62262.php b/hphp/test/zend/good/ext-spl/bug62262.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug62262.php rename to hphp/test/zend/good/ext-spl/bug62262.php diff --git a/hphp/test/zend/bad/ext-spl/bug62262.php.expectf b/hphp/test/zend/good/ext-spl/bug62262.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/bug62262.php.expectf rename to hphp/test/zend/good/ext-spl/bug62262.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/spl_iterator_apply_error_001.php b/hphp/test/zend/good/ext-spl/spl_iterator_apply_error_001.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/spl_iterator_apply_error_001.php rename to hphp/test/zend/good/ext-spl/spl_iterator_apply_error_001.php diff --git a/hphp/test/zend/bad/ext-spl/spl_iterator_apply_error_001.php.expectf b/hphp/test/zend/good/ext-spl/spl_iterator_apply_error_001.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/spl_iterator_apply_error_001.php.expectf rename to hphp/test/zend/good/ext-spl/spl_iterator_apply_error_001.php.expectf diff --git a/hphp/test/zend/bad/ext-spl/spl_recursive_iterator_iterator_key_case.php b/hphp/test/zend/good/ext-spl/spl_recursive_iterator_iterator_key_case.php similarity index 100% rename from hphp/test/zend/bad/ext-spl/spl_recursive_iterator_iterator_key_case.php rename to hphp/test/zend/good/ext-spl/spl_recursive_iterator_iterator_key_case.php diff --git a/hphp/test/zend/bad/ext-spl/spl_recursive_iterator_iterator_key_case.php.expectf b/hphp/test/zend/good/ext-spl/spl_recursive_iterator_iterator_key_case.php.expectf similarity index 100% rename from hphp/test/zend/bad/ext-spl/spl_recursive_iterator_iterator_key_case.php.expectf rename to hphp/test/zend/good/ext-spl/spl_recursive_iterator_iterator_key_case.php.expectf diff --git a/hphp/test/zend/bad/zend/bug60138.php b/hphp/test/zend/good/zend/bug60138.php similarity index 100% rename from hphp/test/zend/bad/zend/bug60138.php rename to hphp/test/zend/good/zend/bug60138.php diff --git a/hphp/test/zend/bad/zend/bug60138.php.expectf b/hphp/test/zend/good/zend/bug60138.php.expectf similarity index 100% rename from hphp/test/zend/bad/zend/bug60138.php.expectf rename to hphp/test/zend/good/zend/bug60138.php.expectf