/**
  * @return void
  */
 public function rewind()
 {
     if ($this->items === null) {
         $this->items = new ArrayIterator($this->slideshow->getItems()->toArray());
     }
     return $this->items->rewind();
 }
 /**
  *
  * @param <type> $table
  * @param ArrayIterator $params
  * @return ArrayObject
  */
 public function search($table, ArrayIterator $params)
 {
     $this->searchParams = $params;
     $this->join();
     if ($table == "analysis") {
         $this->statements->remove("type_event");
     }
     $statement = "SELECT this_.* " . $this->selectAttributes() . " FROM {$table} this_ ";
     $statement .= $this->join();
     $i = 0;
     $this->searchParams->rewind();
     if ($this->searchParams->count() > 0 && !$this->searchParams->offsetExists('true')) {
         $statement .= " WHERE ";
     }
     while ($this->searchParams->valid()) {
         if ($this->statements->containsKey($this->searchParams->key())) {
             if ($i++ > 0) {
                 $statement .= " AND ";
             }
             $clause = $this->statements->get($this->searchParams->key());
             $statement .= str_replace(":" . $this->searchParams->key(), "'" . $this->searchParams->current() . "'", $clause['where']);
         }
         $this->searchParams->next();
     }
     return $this->getObject($statement . " ORDER BY this_.date DESC, this_.id DESC");
 }
 public function rewind()
 {
     parent::rewind();
     if ($this->valid()) {
         $this->sum = parent::current();
     }
 }
Beispiel #4
0
/**
 * 自动加载
 *
 * @param $className
 */
function zroneClassLoader($className)
{
    $path = array(str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "Vendor/"), str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "FrameWork/"), str_replace("\\", "/", dirname(__FILE__) . DIRECTORY_SEPARATOR . "Application/"));
    if (isset($path) && is_array($path)) {
        $Iterator = new ArrayIterator($path);
        $Iterator->rewind();
        $pathString = "";
        while ($Iterator->valid()) {
            $pathString .= $Iterator->current() . ";";
            if ($Iterator->key() == count($path) - 1) {
                $pathString = rtrim($pathString, ";");
            }
            $Iterator->next();
        }
        set_include_path($pathString);
        spl_autoload_extensions(".php, .class.php");
        spl_autoload($className);
    } else {
        try {
            throw new Exception("<code style='color: red; font-size: 22px; display: block; text-align: center; height: 40px; line-height: 40px;'>I'm sorry, my dear! The FrameWork is Wrong……😫</code>");
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
}
Beispiel #5
0
 /** @return php.Iterator */
 protected function nextIterator()
 {
     if ($this->source >= sizeof($this->sources)) {
         return null;
     }
     $src = $this->sources[$this->source];
     // Evaluate lazy supplier functions
     if ($src instanceof \Closure) {
         $src = $src();
     }
     if ($src instanceof \Iterator) {
         $it = $src;
     } else {
         if ($src instanceof \Traversable) {
             $it = new \IteratorIterator($src);
         } else {
             if ($src instanceof XPIterator) {
                 $it = new XPIteratorAdapter($src);
             } else {
                 if (is_array($src)) {
                     $it = new \ArrayIterator($src);
                 } else {
                     if (null === $src) {
                         $it = new \ArrayIterator([]);
                     } else {
                         throw new IllegalArgumentException('Expecting either an iterator, iterable, an array or NULL');
                     }
                 }
             }
         }
     }
     $this->source++;
     $it->rewind();
     return $it;
 }
Beispiel #6
0
 public function rewind()
 {
     parent::rewind();
     if (self::SKIP_FIRST_LINE & $this->getFlags()) {
         $this->next();
     }
 }
Beispiel #7
0
 /**
  * @param string $collection
  * @param array  $query
  *
  * @return \Iterator
  */
 public function find($collection, array $query = [])
 {
     $cursor = $this->getDatabase()->selectCollection($collection)->find($query);
     $iterator = new \ArrayIterator($cursor);
     $iterator->rewind();
     return $iterator;
 }
 public function testRetrievesAndCachesTargetData()
 {
     $ctime = strtotime('January 1, 2013');
     $a = $this->getMockBuilder('SplFileinfo')->setMethods(array('getSize', 'getMTime', '__toString'))->disableOriginalConstructor()->getMock();
     $a->expects($this->any())->method('getSize')->will($this->returnValue(10));
     $a->expects($this->any())->method('getMTime')->will($this->returnValue($ctime));
     $a->expects($this->any())->method('__toString')->will($this->returnValue(''));
     $b = $this->getMockBuilder('SplFileinfo')->setMethods(array('getSize', 'getMTime', '__toString'))->disableOriginalConstructor()->getMock();
     $b->expects($this->any())->method('getSize')->will($this->returnValue(11));
     $b->expects($this->any())->method('getMTime')->will($this->returnValue($ctime));
     $a->expects($this->any())->method('__toString')->will($this->returnValue(''));
     $c = 0;
     $converter = $this->getMockBuilder('Aws\\S3\\Sync\\KeyConverter')->setMethods(array('convert'))->getMock();
     $converter->expects($this->any())->method('convert')->will($this->returnCallback(function () use(&$c) {
         if (++$c == 1) {
             return 'foo';
         } else {
             return 'bar';
         }
     }));
     $targetIterator = new \ArrayIterator(array($b, $a));
     $targetIterator->rewind();
     $changed = new ChangedFilesIterator($targetIterator, $targetIterator, $converter, $converter);
     $ref = new \ReflectionMethod($changed, 'getTargetData');
     $ref->setAccessible(true);
     $this->assertEquals(array(10, $ctime), $ref->invoke($changed, 'bar'));
     $this->assertEquals(array(11, $ctime), $ref->invoke($changed, 'foo'));
     $this->assertFalse($ref->invoke($changed, 'baz'));
 }
 /**
  * @param string null|$aggKey
  * @return array
  */
 public function getAllAggregationColumns($aggKey = null)
 {
     if ($aggKey && isset($this->cachedColumns[$aggKey])) {
         return $this->cachedColumns[$aggKey];
     } elseif ($this->cachedColumns) {
         return $this->cachedColumns;
     }
     foreach (array_column($this->aggregationList, 'index') as $aggIndex) {
         $columns = [];
         $needSort = false;
         foreach ($this->arrayIterator as $current) {
             $aggrItem = $current[$aggIndex];
             if (isset($aggrItem['buckets'])) {
                 foreach ($aggrItem['buckets'] as $bucket) {
                     if (!in_array($bucket['key'], $columns)) {
                         $columns[] = $bucket['key'];
                         $needSort = true;
                     }
                 }
             } else {
                 $columns = array_keys($aggrItem);
                 break;
             }
         }
         $this->arrayIterator->rewind();
         if ($needSort) {
             sort($columns);
         }
         $this->cachedColumns[$aggIndex] = $columns;
     }
     return !is_null($aggKey) && isset($this->cachedColumns[$aggKey]) ? $this->cachedColumns[$aggKey] : $this->cachedColumns;
 }
Beispiel #10
0
 function rewind()
 {
     $this->position = 0;
     parent::rewind();
     if ($this->offset) {
         $this->seek($this->offset);
     }
 }
 public function rewind()
 {
     if ($this->iterator === null) {
         $pdo_fetch_mode = PDO::FETCH_ASSOC;
         switch ($this->fetch_mode) {
             case self::FETCH_NUM:
                 $pdo_fetch_mode = PDO::FETCH_NUM;
                 break;
             case self::FETCH_ASSOC:
             default:
                 $pdo_fetch_mode = PDO::FETCH_ASSOC;
                 break;
         }
         $this->iterator = new ArrayIterator($this->statement->fetchAll($pdo_fetch_mode));
     }
     $this->iterator->rewind();
 }
 public function testRewindRestartsIteratorToBeginning()
 {
     $iterator = new ArrayIterator(array('foo' => 'bar', 'oof' => 'rab'));
     $iterator->next();
     $iterator->rewind();
     $this->assertSame('foo', $iterator->key());
     $this->assertSame('bar', $iterator->current());
 }
 /**
  * {@inheritdoc}
  */
 public function rewind()
 {
     if ($this->iterator) {
         $this->iterator->rewind();
         return;
     }
     $this->iterator = $this->collection->getIterator();
     $this->iterator->rewind();
 }
Beispiel #14
0
 public function __construct($arrToPrint)
 {
     $arrToPrint = (array) $arrToPrint;
     //构造一个循环迭代器
     $aArrIter = new \ArrayIterator($arrToPrint);
     $aArrIter->rewind();
     $this->aArrIter = new \InfiniteIterator($aArrIter);
     $this->aArrIter->rewind();
 }
 public function average(ArrayIterator $values)
 {
     $sum = 0;
     while ($values->valid()) {
         $sum += $values->current();
         $values->next();
     }
     $values->rewind();
     return round($sum / $values->count(), 2);
 }
Beispiel #16
0
 /**
  * @inheritdoc
  */
 public function next()
 {
     $this->iterator->next();
     if ($this->autoloadEnabled && !$this->iterator->valid() && $this->paginator->hasMorePage()) {
         $this->paginator->incrPageNumber();
         /** @var Collection $newCollection */
         $newCollection = $this->adapter->map($this->subject, $this->context)->call($this->method, $this->criteria, $this->paginator);
         $this->iterator = new \ArrayIterator($newCollection->asArray(false));
         $this->iterator->rewind();
     }
 }
 private function getNextRedis()
 {
     // we want the next one
     $this->connectionIterator->next();
     // have to check whether we are at the end
     if (!$this->connectionIterator->valid()) {
         // if so we go back to the start
         $this->connectionIterator->rewind();
     }
     // now we are sure that we have a valid item
     return $this->connectionIterator->current();
 }
Beispiel #18
0
 /**
  * set next task to execute in current job
  * @param $taskPID task PID (Process ID)
  * @return boolean whether skip is possible
  */
 public function skipTo($taskPID)
 {
     $this->taskSkip = true;
     $this->tasksIterator->rewind();
     while ($this->tasksIterator->valid()) {
         $task = $this->tasksIterator->current();
         if ($task->pid == $taskPID) {
             return;
         }
         $this->tasksIterator->next();
     }
 }
Beispiel #19
0
 protected function assertIteratesThrough($values, $iterator)
 {
     $valuesIterator = new ArrayIterator($values);
     $valuesIterator->rewind();
     foreach ($iterator as $key => $row) {
         $this->assertTrue($valuesIterator->valid());
         $this->assertEquals($valuesIterator->key(), $key);
         $this->assertEquals($valuesIterator->current(), $row);
         $valuesIterator->next();
     }
     $this->assertFalse($valuesIterator->valid());
 }
 function rewind()
 {
     $this->position = 0;
     parent::rewind();
     // goto offset item if possible
     if ($this->offset) {
         try {
             $this->seek($this->offset);
         } catch (OutOfBoundsException $e) {
             $this->seek($this->count() - 1);
             $this->next();
         }
     }
 }
Beispiel #21
0
 /**
  * Returns the next bunch in line.
  *
  * @return array
  */
 public function getNextBunch()
 {
     if ($this->_iterator === null) {
         $this->_iterator = $this->getIterator();
         $this->_iterator->rewind();
     }
     if ($this->_iterator->valid()) {
         $dataRow = $this->_iterator->current();
         $this->_iterator->next();
     } else {
         $this->_iterator = null;
         $dataRow = null;
     }
     return $dataRow;
 }
Beispiel #22
0
 function testSeek()
 {
     $iterator = new ArrayIterator([0, 5, 2, 6]);
     $iterator->rewind();
     $iterator->seek(3);
     $this->assertEquals(6, $iterator->current());
     $iterator->seek(1);
     $this->assertEquals(5, $iterator->current());
     $iterator->seek(2);
     $this->assertEquals(2, $iterator->current());
     $iterator->seek(0);
     $this->assertEquals(0, $iterator->current());
     $iterator->seek(3);
     $this->assertEquals(6, $iterator->current());
 }
Beispiel #23
0
 protected function assertIteratesThrough($values, $iterator)
 {
     $valuesIterator = new ArrayIterator($values);
     $valuesIterator->rewind();
     foreach ($iterator as $key => $row) {
         foreach ($row as &$value) {
             if ($value instanceof DateTime) {
                 $value = $value->format('Y-m-d H:i');
             }
         }
         $this->assertTrue($valuesIterator->valid());
         $this->assertEquals($valuesIterator->key(), $key);
         $this->assertEquals($valuesIterator->current(), $row);
         $valuesIterator->next();
     }
     $this->assertFalse($valuesIterator->valid());
 }
Beispiel #24
0
function dump($data, $depth = 0)
{
    if (is_array($data)) {
        print_line('[', $depth);
        foreach ($data as $key => $value) {
            if (!is_int($key)) {
                print_line("{$key} =>", $depth + 1);
            }
            dump($value, $depth + 2);
        }
        print_line(']', $depth);
        return;
    }
    if (is_object($data)) {
        if (method_exists($data, '__toString')) {
            $class = get_class($data);
            print_line("[{$class}] {$data}", $depth);
            return;
        }
        $class = get_class($data);
        print_line("[{$class}] {", $depth);
        if ($data instanceof \IteratorAggregate) {
            $iterator = $data->getIterator();
        } elseif ($data instanceof \Iterator) {
            $iterator = $data;
        } else {
            $iterator = new \ArrayIterator((array) $data);
        }
        for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
            if (!is_int($iterator->key())) {
                dump($iterator->key(), $depth + 1);
            }
            dump($iterator->current(), $depth + 2);
        }
        print_line('}', $depth);
        return;
    }
    if (is_string($data)) {
        print_line('"' . $data . '"', $depth);
        return;
    }
    print_line($data, $depth);
}
 /**
  * fetches collection for particular page
  * @param $page
  * @throws ResourceException
  */
 protected function fetch($page)
 {
     $resourceCopy = clone $this->resource;
     $resourceCopy->page($page);
     // save up the memory; GC hack?
     $this->collection = null;
     $this->iterator = null;
     try {
         $this->collection = $resourceCopy->get();
         // empty collection received
     } catch (Resource\Exception\NotFoundException $ex) {
         $object = new \ArrayObject();
         $object->count = 0;
         $object->pages = 0;
         $object->page = 1;
         $this->collection = $object;
     }
     $this->iterator = new \ArrayIterator($this->collection);
     $this->iterator->rewind();
 }
 /**
  * Rewinds the cache entry iterator to the first element
  * and fetches cacheEntries.
  *
  * @return void
  * @api
  */
 public function rewind()
 {
     if ($this->cacheEntriesIterator === null) {
         $cacheEntries = [];
         $statementHandle = $this->databaseHandle->prepare('SELECT "identifier", "content" FROM "cache" WHERE "context"=? AND "cache"=?' . $this->getNotExpiredStatement());
         $statementHandle->execute(array($this->context, $this->cacheIdentifier));
         $fetchedColumns = $statementHandle->fetchAll();
         foreach ($fetchedColumns as $fetchedColumn) {
             // Convert hexadecimal data into binary string,
             // because it is not allowed to store null bytes in PostgreSQL.
             if ($this->pdoDriver === 'pgsql') {
                 $fetchedColumn['content'] = hex2bin($fetchedColumn['content']);
             }
             $cacheEntries[$fetchedColumn['identifier']] = $fetchedColumn['content'];
         }
         $this->cacheEntriesIterator = new \ArrayIterator($cacheEntries);
     } else {
         $this->cacheEntriesIterator->rewind();
     }
 }
 /**
  * Sets the iterator back to the first element
  *
  * @return void
  */
 public function rewind()
 {
     $this->iteratorCacheIterator->rewind();
 }
 /**
  * {@inheritdoc}
  */
 public function initialize()
 {
     if (null !== $this->yaml) {
         $this->yaml->rewind();
     }
 }
 function rewind()
 {
     echo __METHOD__ . "\n";
     parent::rewind();
 }
 public function rewind()
 {
     $this->_iterator = null;
     parent::rewind();
     $this->setInner();
 }