/** * 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(); } }
public function valid() { get_next: // Return true if this function has already been called for iteration. if ($this->currentRequest) { return true; } // Return false if we are at the end of the provided commands iterator. if (!$this->commands->valid()) { return false; } $command = $this->commands->current(); if (!$command instanceof CommandInterface) { throw new \RuntimeException('All commands provided to the ' . __CLASS__ . ' must implement GuzzleHttp\\Command\\CommandInterface.' . ' Encountered a ' . Core::describeType($command) . ' value.'); } $command->setFuture('lazy'); $this->attachListeners($command, $this->eventListeners); // Prevent transfer exceptions from throwing. $command->getEmitter()->on('process', function (ProcessEvent $e) { if ($e->getException()) { $e->setResult(null); } }, RequestEvents::LATE); $builder = $this->requestBuilder; $result = $builder($command); // Skip commands that were intercepted with a result. if (isset($result['result'])) { $this->commands->next(); goto get_next; } $this->currentRequest = $result['request']; return true; }
private function valid() { if (!$this->data->valid()) { $this->rewind(); } return TRUE; }
/** * {@inheritdoc} */ public function next() { $this->neighbour->next(); if (!$this->neighbour->valid()) { $this->neighbour->rewind(); parent::next(); } }
public function valid(){ if ($this->isFirstValidCall === true){ $this->innerHasItems = $this->innerIterator->valid(); $this->isFirstValidCall = false; return true; } return $this->innerIterator->valid(); }
public function next() { $this->currentIt->next(); if ($this->state === 1 && !$this->currentIt->valid()) { $this->currentIt = $this->it2; $this->state = 2; } }
private function memo() { if (!$this->it->valid()) { return; } array_push($this->cache, array($this->it->key(), $this->it->current())); $this->cacheSize++; }
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); } }
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 valid() { if (!parent::valid()) { if ($this->source->valid()) { $this->append($this->transform($this->source->current())); } } return parent::valid(); }
/** * @return string */ public function dir_readdir() { if ($this->iterator->valid()) { $result = $this->iterator->current(); $this->iterator->next(); return $result; } else { return false; } }
/** * Initialize isSuspended. * * Called in walk() method. * * @return void */ protected function initSuspended() { if ($this->lineHandler instanceof \IteratorIterator) { $this->isSuspended = $this->lineHandler->getInnerIterator()->valid(); } elseif ($this->lineHandler instanceof \Iterator) { $this->isSuspended = $this->lineHandler->valid(); } else { $this->isSuspended = false; } }
/** * @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; }
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(); } }
public function valid() { if ($this->usingCache) { return isset($this->array[$this->position]); } $valid = $this->innerIterator->valid(); if (!$valid) { $this->usingCache = true; } return $valid; }
/** * @param \Iterator $result * @param \Iterator $expected */ protected function equalsProjections(\Iterator $result, \Iterator $expected) { $result->rewind(); $expected->rewind(); while ($result->valid() && $expected->valid()) { $this->given($resultValue = $result->current(), $expectedValue = $expected->current())->then()->object($resultValue->projection())->isEqualTo($expectedValue->projection()); $result->next(); $expected->next(); } $this->then()->boolean($result->valid())->isFalse()->boolean($expected->valid())->isFalse(); }
function it_adds_an_address_when_different_than_the_ones_present_on_the_customer(AddressComparatorInterface $addressComparator, CustomerInterface $customer, AddressInterface $customerAddress, AddressInterface $newAddress, Collection $addresses, \Iterator $iterator) { $iterator->rewind()->shouldBeCalled(); $iterator->valid()->willReturn(true); $iterator->current()->willReturn($customerAddress); $iterator->valid()->willReturn(false); $addresses->getIterator()->willReturn($iterator); $customer->getAddresses()->willReturn($addresses); $addressComparator->equal($customerAddress, $newAddress)->willReturn(false); $customer->addAddress($newAddress)->shouldBeCalled(); $this->add($customer, $newAddress); }
function it_scores_traversable_object_from_value_token(TokenInterface $value, \Iterator $object) { $object->current()->will(function ($args, $object) { $object->valid()->willReturn(false); return 'value'; }); $object->key()->willReturn('key'); $object->rewind()->willReturn(null); $object->next()->willReturn(null); $object->valid()->willReturn(true); $value->scoreArgument('value')->willReturn(2); $this->scoreArgument($object)->shouldBe(2); }
/** * @inheritdoc */ public function current() { $current = $this->delegatorReader->current(); if (!$current) { $this->iterator->next(); if (!$this->iterator->valid()) { return false; } $resource = $this->convertResource($this->resource, $this->iterator->current()); $this->delegatorReader->open($resource); return $this->current(); } return $current; }
/** * @return Generator */ private function iterateAndCache() { foreach ($this->cache as $key => $value) { (yield $key => $value); } if ($this->innerIterator !== null) { while ($this->innerIterator->valid()) { $this->cache[$this->innerIterator->key()] = $this->innerIterator->current(); (yield $this->innerIterator->key() => $this->innerIterator->current()); $this->innerIterator->next(); } $this->innerIterator = null; } }
/** * Internally increments the iterator and saves the value * * @return Boolean Returns whether the iterator returned a valid value */ private function storeNext() { if (!isset($this->iterator)) { return FALSE; } else { if ($this->iterator->valid()) { $this->cache[$this->internalOffset] = array($this->iterator->key(), $this->iterator->current()); return TRUE; } else { unset($this->iterator); return FALSE; } } }
public function read() { if (!isset($this->iterator)) { $this->initializeIterator(); } if (!$this->iterator->valid()) { return null; } $current = $this->iterator->current(); if ($this->stepExecution) { $this->stepExecution->incrementSummaryInfo('read'); } $this->iterator->next(); return $current; }
public function valid(){ while($this->innerIterator->valid() === true){ if ($this->projectionNeeded === true){ $this->project(); $this->currentIterator->rewind(); } if ($this->currentIterator->valid() === true){ return true; } else { $this->innerIterator->next(); $this->projectionNeeded = true; } } return false; }
/** * (PHP 5 >= 5.0.0)<br/> * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return array Can return any type. */ public function current() { if ($this->currentGroup == null) { $left = $this->groupSize; $this->currentGroup = array(); while ($this->innerIterator->valid()) { if ($left-- <= 0) { break; } $this->currentGroup[] = $this->innerIterator->current(); $this->innerIterator->next(); } } return $this->currentGroup; }
public function read() { if (!isset($this->iterator)) { $this->initializeIterator(); } if (!$this->iterator->valid()) { return null; } $current = $this->iterator->current(); if ($this->stepExecution) { $this->stepExecution->incrementSummaryInfo('read'); } $this->iterator->next(); return $this->convertNumericIdentifierToString($current); }
private function deleteRemainingDestinationObjects() { while ($this->destinationQueue->valid()) { $this->delete($this->destinationQueue->current()); $this->notifyProgress(); } }
private function advanceElementIterator(\Iterator $element) { $element->next(); if (!$element->valid()) { next($this->fields); } }
/** * @param \Iterator $operatorChain * @param \Iterator $input * * @return \ArrayIterator */ private function solveIntermediateOperationChain(\Iterator $operatorChain, \Iterator $input) { $results = new \ArrayIterator(); $input->rewind(); $continueWIthNextItem = true; while ($input->valid() && $continueWIthNextItem) { $result = $input->current(); $useResult = true; // do the whole intermediate operation chain for the current input $operatorChain->rewind(); while ($operatorChain->valid() && $useResult) { /** @var IntermediateOperationInterface $current */ $current = $operatorChain->current(); // apply intermediate operations $result = $current->apply($result, $input->key(), $useResult, $returnedCanContinue); // track the continuation flags $continueWIthNextItem = $continueWIthNextItem && $returnedCanContinue; // iterate $operatorChain->next(); } if ($useResult) { $results->append($result); } // goto next item $input->next(); } return $results; }
/** * Returns whether the iterator currently has a valid value * * @return Boolean */ public function valid() { if ($this->valid === NULL) { $this->valid = (bool) $this->inner->valid(); } return $this->valid; }
/** * Internal method for creating the next group * * @return NULL */ private function createGroup() { $this->key = NULL; if (!$this->inner->valid()) { $this->current = NULL; return; } $this->current = array(); do { $current = $this->inner->current(); $key = $this->extractKey($current); // If a key was found, add it to the current group until it changes if (!empty($key)) { if (!isset($this->key)) { $this->key = $key; } if ($key != $this->key) { break; } $this->current[] = $current; } $this->inner->next(); } while ($this->inner->valid()); // We can get here if they gave us a grouping field that didn't exist // in any of the iterator values if (empty($this->current)) { $this->current = NULL; } else { $this->current = new \ArrayIterator($this->current); } }