Exemplo n.º 1
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();
     }
 }
 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;
 }
Exemplo n.º 3
0
 private function valid()
 {
     if (!$this->data->valid()) {
         $this->rewind();
     }
     return TRUE;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function next()
 {
     $this->neighbour->next();
     if (!$this->neighbour->valid()) {
         $this->neighbour->rewind();
         parent::next();
     }
 }
Exemplo n.º 5
0
	public function valid(){
		if ($this->isFirstValidCall === true){
			$this->innerHasItems = $this->innerIterator->valid();
			$this->isFirstValidCall = false;
			return true;
		}
		return $this->innerIterator->valid();
	}
Exemplo n.º 6
0
 public function next()
 {
     $this->currentIt->next();
     if ($this->state === 1 && !$this->currentIt->valid()) {
         $this->currentIt = $this->it2;
         $this->state = 2;
     }
 }
Exemplo n.º 7
0
 private function memo()
 {
     if (!$this->it->valid()) {
         return;
     }
     array_push($this->cache, array($this->it->key(), $this->it->current()));
     $this->cacheSize++;
 }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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);
     }
 }
Exemplo n.º 10
0
 public function valid()
 {
     if (!parent::valid()) {
         if ($this->source->valid()) {
             $this->append($this->transform($this->source->current()));
         }
     }
     return parent::valid();
 }
Exemplo n.º 11
0
 /**
  * @return string
  */
 public function dir_readdir()
 {
     if ($this->iterator->valid()) {
         $result = $this->iterator->current();
         $this->iterator->next();
         return $result;
     } else {
         return false;
     }
 }
Exemplo n.º 12
0
 /**
  * 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;
     }
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
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();
     }
 }
Exemplo n.º 15
0
 public function valid()
 {
     if ($this->usingCache) {
         return isset($this->array[$this->position]);
     }
     $valid = $this->innerIterator->valid();
     if (!$valid) {
         $this->usingCache = true;
     }
     return $valid;
 }
Exemplo n.º 16
0
 /**
  * @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);
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 19
0
 /**
  * @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;
 }
Exemplo n.º 20
0
 /**
  * @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;
     }
 }
Exemplo n.º 21
0
 /**
  * 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;
	}
Exemplo n.º 24
0
 /**
  * (PHP 5 &gt;= 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);
 }
Exemplo n.º 26
0
 private function deleteRemainingDestinationObjects()
 {
     while ($this->destinationQueue->valid()) {
         $this->delete($this->destinationQueue->current());
         $this->notifyProgress();
     }
 }
Exemplo n.º 27
0
 private function advanceElementIterator(\Iterator $element)
 {
     $element->next();
     if (!$element->valid()) {
         next($this->fields);
     }
 }
Exemplo n.º 28
0
 /**
  * @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;
 }
Exemplo n.º 29
0
 /**
  * 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;
 }
Exemplo n.º 30
0
 /**
  * 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);
     }
 }