Skip to content

Commit

Permalink
implement RecursiveArrayIterator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptarjan authored and sgolemon committed Jul 23, 2013
1 parent 10dacc2 commit 9ce7792
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions hphp/NEWS
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 3 additions & 1 deletion hphp/system/php.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions hphp/system/php/spl/iterators/RecursiveArrayIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.recursivearrayiterator.php
* )
*
* This iterator allows to unset and modify values and keys while
* iterating over Arrays and Objects in the same way as the ArrayIterator.
* Additionally it is possible to iterate over the current iterator entry.
*
*/
class RecursiveArrayIterator
extends ArrayIterator
implements RecursiveIterator {

const CHILD_ARRAYS_ONLY = 4;

// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from
* http://php.net/manual/en/recursivearrayiterator.getchildren.php )
*
* Returns an iterator for the current iterator entry.
*
* @return mixed An iterator for the current entry, if it is an array
* or object.
*/
public function getChildren() {
return new RecursiveArrayIterator(
$this->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);
}

}
6 changes: 3 additions & 3 deletions hphp/system/php/spl/iterators/RecursiveIteratorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function __construct($iterator,
*/
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;
Expand Down Expand Up @@ -200,7 +200,7 @@ public function valid() {

$it = $this->getInnerIterator();
if ($it->valid() &&
$it->isDir() &&
$it->hasChildren() &&
($this->mode == self::LEAVES_ONLY ||
($this->mode == self::CHILD_FIRST &&
$this->getInnerIteratorFlag() == 0))) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9ce7792

Please sign in to comment.