/**
  * {@inheritdoc}
  */
 public function rewind()
 {
     if (!$this->iterator) {
         $this->initIterator();
     }
     $this->iterator->rewind();
 }
Esempio n. 2
0
 private function valid()
 {
     if (!$this->data->valid()) {
         $this->rewind();
     }
     return TRUE;
 }
Esempio n. 3
0
 /**
  * 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();
     }
 }
 private function getCurrentIterator()
 {
     if (null === $this->currentIterator) {
         $this->currentIterator = $this->mainIterator->current();
     }
     return $this->currentIterator;
 }
 /**
  * {@inheritdoc}
  */
 public final function rewind()
 {
     if (null === $this->iterator) {
         throw new \LogicException('Internal iterator is missing.');
     }
     $this->iterator->rewind();
 }
 /**
  * {@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)));
     }
 }
 /**
  * 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();
 }
 public function getChildren()
 {
     $children = new self($this->iterator->getChildren(), []);
     $children->excludedDirs = $this->excludedDirs;
     $children->excludedPattern = $this->excludedPattern;
     return $children;
 }
Esempio n. 9
0
 private function advanceElementIterator(\Iterator $element)
 {
     $element->next();
     if (!$element->valid()) {
         next($this->fields);
     }
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function rewind()
 {
     if (!$this->iterableResult) {
         $this->iterableResult = new \ArrayIterator($this->getDataFromService());
     }
     $this->iterableResult->rewind();
 }
Esempio n. 11
0
 /**
  * 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);
     }
 }
Esempio n. 12
0
 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();
     }
 }
Esempio n. 13
0
/**
 *
 */
function foo(Iterator $param)
{
    if ($param->valid()) {
        echo 'valid';
    } else {
        echo 'invalid';
    }
}
	public function valid(){
		if ($this->isFirstValidCall === true){
			$this->innerHasItems = $this->innerIterator->valid();
			$this->isFirstValidCall = false;
			return true;
		}
		return $this->innerIterator->valid();
	}
Esempio n. 15
0
 public static function baa(Iterator $param)
 {
     if ($param->valid()) {
         echo 'valid';
     } else {
         echo 'invalid';
     }
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     if ($this->sortedIterator === null) {
         $this->sortedIterator = new \ArrayIterator($this->enumerable()->toArray(true));
         $this->sortedIterator->uasort($this->comparator());
     }
     return $this->sortedIterator;
 }
Esempio n. 17
0
 private function memo()
 {
     if (!$this->it->valid()) {
         return;
     }
     array_push($this->cache, array($this->it->key(), $this->it->current()));
     $this->cacheSize++;
 }
 /**
  * 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();
 }
Esempio n. 19
0
 private function fetch()
 {
     if ($this->it->valid()) {
         $this->v = $this->it->current();
         $this->k = $this->it->key();
         $fn = $this->fn;
         $fn($this->v, $this->k);
     }
 }
Esempio n. 20
0
 /**
  * @param \Iterator $cursor
  *
  * @return array
  */
 public function fetch(\Iterator $cursor)
 {
     $data = [];
     if ($cursor->valid()) {
         $data = $cursor->current();
         $cursor->next();
     }
     return $data;
 }
Esempio n. 21
0
 private function fetch()
 {
     if ($this->it->valid()) {
         $v = $this->it->current();
         $k = $this->it->key();
         $this->v = $this->valueSelector->select($v, $k);
         $this->k = $this->keySelector->select($v, $k);
     }
 }
 public function fetch($fetchMode = null)
 {
     if (!$this->currentIterator) {
         $this->currentIterator = $this->getIterator();
     }
     $data = $this->currentIterator->current();
     $this->currentIterator->next();
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 protected function doMatch($name, \Iterator $subject, $expected, $elementNumber)
 {
     list($expectedKey, $expectedValue) = $this->castArgumentToKeyValueTuple($expected);
     $actualKey = $subject->key();
     $actualValue = $subject->current();
     if ($expectedKey !== $actualKey || $expectedValue !== $actualValue) {
         throw new FailureException(sprintf('Element #%d was expected to have key %s with value %s, but key %s with value %s was given.', $elementNumber, $this->presenter->presentValue($expectedKey), $this->presenter->presentValue($expectedValue), $this->presenter->presentValue($actualKey), $this->presenter->presentValue($actualValue)));
     }
 }
Esempio n. 24
0
 /**
  * ( excerpt from http://php.net/manual/en/appenditerator.append.php )
  *
  * Appends an iterator.
  *
  * @it         mixed   The iterator to append.
  *
  * @return     mixed   No value is returned.
  */
 function append(\Iterator $it)
 {
     $it->rewind();
     $this->iterators->append($it);
     // if we will start at $it and $it is empty, advance our position past
     if ($this->iterators->current() === $it && !$it->valid()) {
         $this->iterators->next();
     }
 }
Esempio n. 25
0
 public function valid()
 {
     if (!parent::valid()) {
         if ($this->source->valid()) {
             $this->append($this->transform($this->source->current()));
         }
     }
     return parent::valid();
 }
Esempio n. 26
0
 /**
  * @param $limit
  * @return Resource[]
  */
 public function collect($limit = -1)
 {
     $resources = array();
     while ($limit && $this->iterator->valid()) {
         $resources[] = $this->iterator->current();
         $this->iterator->next();
         $limit--;
     }
     return $resources;
 }
Esempio n. 27
0
 /**
  * {@inheritdoc}
  */
 public function rewind()
 {
     if (!$this->iterableResult) {
         $this->iterableResult = new \SimpleXMLIterator(file_get_contents($this->filename));
         if ($this->xpath) {
             $this->iterableResult = new \ArrayIterator($this->iterableResult->xpath($this->xpath));
         }
     }
     $this->iterableResult->rewind();
 }
Esempio n. 28
0
 protected function fetch()
 {
     $this->buffer = array();
     for ($i = 0; $i < $this->chunkSize; $i++) {
         if (!$this->it->valid()) {
             return;
         }
         array_push($this->buffer, $this->it->current());
         $this->it->next();
     }
 }
Esempio n. 29
0
 public function valid()
 {
     if ($this->usingCache) {
         return isset($this->array[$this->position]);
     }
     $valid = $this->innerIterator->valid();
     if (!$valid) {
         $this->usingCache = true;
     }
     return $valid;
 }
Esempio n. 30
0
function iterateList(Iterator $i)
{
    foreach ($i as $entry) {
        if ($i->hasChildren() && !ignore($entry)) {
            iterateList($i->getChildren());
        } else {
            if (substr($entry, -4, 4) == '.php') {
                checkFile($entry);
            }
        }
    }
}