Implement EmptyIterator, InfiniteIterator, NoRewindIterator

This makes 14 zend tests happy. It also requires some
real stupidity, but PHP iterators are weird.
Esse commit está contido em:
Eric Caruso
2013-06-25 10:43:33 -07:00
commit de Sara Golemon
commit 4a86eb9f1f
33 arquivos alterados com 223 adições e 4 exclusões
+3
Ver Arquivo
@@ -65,6 +65,9 @@ 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
hphp/system/php/spl/iterators/NoRewindIterator.php
hphp/system/php/spl/iterators/RecursiveIteratorIterator.php
hphp/system/php/spl/miscellaneous/ArrayObject.php
@@ -0,0 +1,77 @@
<?php
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.emptyiterator.php )
*
* The EmptyIterator class for an empty iterator.
*
*/
class EmptyIterator implements Iterator {
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/emptyiterator.current.php )
*
* This function must not be called. It throws an exception upon access.
* Warning: This function is currently not documented; only its argument
* list is available.
*
* @return mixed No value is returned.
*/
public function current() {
throw new BadMethodCallException(
"Accessing the value of an EmptyIterator");
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/emptyiterator.key.php )
*
* This function must not be called. It throws an exception upon access.
* Warning: This function is currently not documented; only its argument
* list is available.
*
* @return mixed No value is returned.
*/
public function key() {
throw new BadMethodCallException(
"Accessing the key of an EmptyIterator");
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/emptyiterator.next.php )
*
* No operation, nothing to do. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed No value is returned.
*/
public function next() {}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/emptyiterator.rewind.php )
*
* No operation, nothing to do. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed No value is returned.
*/
public function rewind() {}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/emptyiterator.valid.php )
*
* The EmptyIterator valid() method. Warning: This function is currently
* not documented; only its argument list is available.
*
* @return mixed FALSE
*/
public function valid() {
return false;
}
}
@@ -0,0 +1,53 @@
<?php
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.infiniteiterator.php )
*
* The InfiniteIterator allows one to infinitely iterate over an iterator
* without having to manually rewind the iterator upon reaching its end.
*
*/
class InfiniteIterator extends IteratorIterator implements OuterIterator {
private $valid;
public function rewind() {
$iter = $this->getInnerIterator();
$this->_setPosition(0);
$iter->rewind();
$this->valid = $this->_fetch(true);
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/infiniteiterator.next.php )
*
* Moves the inner Iterator forward to its next element if there is one,
* otherwise rewinds the inner Iterator back to the beginning.
*
* Even an InfiniteIterator stops if its inner Iterator is empty.
*
* @return mixed No value is returned.
*/
public function next() {
$iter = $this->getInnerIterator();
$this->_setPosition($this->_getPosition() + 1);
$iter->next();
if ($iter->valid()) {
$this->valid = $this->_fetch(false);
} else {
$this->_setPosition(0);
$iter->rewind();
if ($iter->valid()) {
$this->valid = $this->_fetch(false);
}
}
}
public function valid() {
return $this->valid;
}
}
@@ -15,7 +15,6 @@ class IteratorIterator implements OuterIterator {
private $iterator;
private $current;
private $key;
private $valid;
private $position;
// This doc comment block generated by idl/sysdoc.php
@@ -101,7 +100,7 @@ class IteratorIterator implements OuterIterator {
*/
public function next() {
$this->iterator->next();
$this->_position++;
$this->position++;
$this->_fetch(true);
return;
}
@@ -116,7 +115,7 @@ class IteratorIterator implements OuterIterator {
*/
public function rewind() {
$this->iterator->rewind();
$this->_position = 0;
$this->position = 0;
$this->_fetch(true);
return;
}
@@ -139,7 +138,7 @@ class IteratorIterator implements OuterIterator {
if (!$check || $this->iterator->valid()) {
$this->current = $this->iterator->current();
$key = $this->iterator->key();
$this->key = is_null($key) ? $this->_position : $key;
$this->key = is_null($key) ? $this->position : $key;
return true;
}
return false;
@@ -0,0 +1,87 @@
<?php
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/class.norewinditerator.php )
*
* This iterator cannot be rewound.
*
*/
class NoRewindIterator extends IteratorIterator {
private $current;
private $key;
private $needsRefresh;
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/norewinditerator.construct.php )
*
* Constructs a NoRewindIterator.
*
* @iterator mixed The iterator being used.
*
* @return mixed A NoRewindIterator() based on the passed in
* iterator.
*/
public function __construct($iterator) {
parent::__construct($iterator);
$this->needsRefresh = true;
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/norewinditerator.current.php )
*
* Gets the current value. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed The current value.
*/
public function current() {
if ($this->needsRefresh) {
$this->current = $this->getInnerIterator()->current();
}
$this->needsRefresh = false;
return $this->current;
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/norewinditerator.key.php )
*
* Gets the current key. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed The current key.
*/
public function key() {
return $this->getInnerIterator()->key();
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/norewinditerator.rewind.php )
*
* Prevents the rewind operation on the inner iterator.
*
* @return mixed No value is returned.
*/
public function rewind() {
}
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from http://php.net/manual/en/norewinditerator.next.php )
*
* Forwards to the next element. Warning: This function is currently not
* documented; only its argument list is available.
*
* @return mixed No value is returned.
*/
public function next() {
$this->getInnerIterator()->next();
$this->needsRefresh = true;
}
}