本文整理汇总了PHP中Iterator类的典型用法代码示例。如果您正苦于以下问题:PHP Iterator类的具体用法?PHP Iterator怎么用?PHP Iterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkStemmer
protected function checkStemmer(Stemmer $stemmer, \Iterator $words, \Iterator $stems)
{
foreach ($words as $word) {
$stem = $stems->current();
$this->assertEquals($stemmer->stem($word), $stem, "The stem for '{$word}' should be '{$stem}' not '{$stemmer->stem($word)}'");
$stems->next();
}
}
示例2: rewind
/**
* {@inheritdoc}
*/
public function rewind()
{
if (!$this->iterator) {
$this->initIterator();
}
$this->iterator->rewind();
}
示例3: getCurrentIterator
private function getCurrentIterator()
{
if (null === $this->currentIterator) {
$this->currentIterator = $this->mainIterator->current();
}
return $this->currentIterator;
}
示例4: doMatch
/**
* {@inheritdoc}
*/
protected function doMatch($name, \Iterator $subject, $expected, $elementNumber)
{
$actual = $subject->current();
if ($expected !== $actual) {
throw new FailureException(sprintf('Element #%d was expected to be %s, but %s was given.', $elementNumber, $this->presenter->presentValue($expected), $this->presenter->presentValue($actual)));
}
}
示例5: rewind
/**
* Rewind the Iterator to the first element.
*
* @link http://php.net/manual/en/iterator.rewind.php
* @since 5.0.0
*/
public function rewind()
{
if (null === $this->iterator) {
throw new \LogicException('Missing internal iterator.');
}
$this->iterator->rewind();
}
示例6: advanceElementIterator
private function advanceElementIterator(\Iterator $element)
{
$element->next();
if (!$element->valid()) {
next($this->fields);
}
}
示例7: rewind
/**
* {@inheritdoc}
*/
public function rewind()
{
if (!$this->iterableResult) {
$this->iterableResult = new \ArrayIterator($this->getDataFromService());
}
$this->iterableResult->rewind();
}
示例8: indexDatabase
/**
* Builds the index for the given collection
*
* @param DatabaseInterface|\Iterator $database
* @return $this
*/
public function indexDatabase($database)
{
// Clear the map
$this->map = array();
/** @var SplFixedArray $collection */
$collection = null;
if ($database instanceof DatabaseRawDataInterface) {
$collection = $database->getRawData();
}
if ($database instanceof SplFixedArray) {
// Use the fixed array as is
} elseif (is_array($database)) {
$collection = SplFixedArray::fromArray($database);
} elseif ($database instanceof \Iterator) {
$collection = SplFixedArray::fromArray(iterator_to_array($database));
} else {
throw new InvalidIndexException(sprintf('Can not build index of argument of type %s', is_object($database) ? get_class($database) : gettype($database)));
}
$position = 0;
$count = $collection->getSize();
if ($count > 0) {
do {
$tempEntry = DocumentUtility::assertDocumentIdentifier($database[$position]);
$this->addEntryWithPosition($tempEntry, $position);
} while (++$position < $count);
}
}
示例9: foo
/**
*
*/
function foo(Iterator $param)
{
if ($param->valid()) {
echo 'valid';
} else {
echo 'invalid';
}
}
示例10: valid
public function valid(){
if ($this->isFirstValidCall === true){
$this->innerHasItems = $this->innerIterator->valid();
$this->isFirstValidCall = false;
return true;
}
return $this->innerIterator->valid();
}
示例11: baa
public static function baa(Iterator $param)
{
if ($param->valid()) {
echo 'valid';
} else {
echo 'invalid';
}
}
示例12: getIterator
/**
* {@inheritdoc}
*/
public function getIterator()
{
if ($this->sortedIterator === null) {
$this->sortedIterator = new \ArrayIterator($this->enumerable()->toArray(true));
$this->sortedIterator->uasort($this->comparator());
}
return $this->sortedIterator;
}
示例13: initializeIterator
/**
* Initializes the iterator
*/
protected function initializeIterator()
{
$this->iterator = $this->createIterator();
if ($this->batchMode) {
$this->iterator = new \ArrayIterator(array(iterator_to_array($this->iterator)));
}
$this->iterator->rewind();
}
示例14: fetch
/**
* @param \Iterator $cursor
*
* @return array
*/
public function fetch(\Iterator $cursor)
{
$data = [];
if ($cursor->valid()) {
$data = $cursor->current();
$cursor->next();
}
return $data;
}
示例15: lazyAppend
/**
* Lazily append the next iterator to the chain
*/
private function lazyAppend()
{
if (!parent::valid() and $this->iterators->valid()) {
$this->append($this->iterators->current());
$this->iterators->next();
}
}