Example #1
0
 /**
  * Fetch Next Token
  *
  * @return Token
  */
 public function pop()
 {
     if ($token = $this->peeked) {
         $this->peeked = null;
         return $token;
     }
     $token = $this->generator->current();
     $this->generator->next();
     return $token;
 }
Example #2
0
 public function next()
 {
     if ($this->_currentGen) {
         return $this->_currentGen->next();
     }
     return next($this->_records);
 }
 /**
  * Rewind the Iterator to the first element
  * @see Iterator::rewind
  * @link http://php.net/manual/en/iterator.rewind.php
  */
 public function rewind()
 {
     $this->generateGenerator();
     if (is_callable($this->onRewind)) {
         call_user_func($this->onRewind);
     }
     if (defined('HHVM_VERSION')) {
         $this->generator->next();
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function read($length)
 {
     $this->initializeBeforeRead();
     if (!$this->generator->valid()) {
         return '';
     }
     if ($this->resource->eof()) {
         $this->generator->next();
         if (!$this->generator->valid()) {
             return '';
         }
         $this->resource = $this->generator->current();
         $this->resource->rewind();
     }
     return $this->resource->fread($length);
 }
Example #5
0
 /**
  * Moves the generator on by one token.
  *
  * (It calls ->next() on the generator, look at the PHP doc)
  *
  * @see \Generator->next
  *
  * @return $this
  */
 protected function nextToken()
 {
     $this->tokens->next();
     return $this;
 }
/**
 *
 * @param int $n
 * @param \Generator $gen
 *
 * @return \Generator
 */
function take($n, Generator $gen)
{
    while ($n-- > 0 && $gen->valid()) {
        (yield $gen->current());
        $gen->next();
    }
}
Example #7
0
 public function next()
 {
     if (!$this->generator) {
         $this->rewind();
     }
     $this->generator->next();
 }
Example #8
0
 /**
  * @param \Generator $logs
  *
  * @return int
  */
 protected function cntGeneratorLogs($logs)
 {
     $cnt = 0;
     while ($logs->valid()) {
         $cnt++;
         $logs->next();
     }
     return $cnt;
 }
Example #9
0
 /**
  * Get next item
  */
 public function next()
 {
     if ($this->generator) {
         $this->generator->next();
     }
 }