/**
  * @inheritDoc
  */
 public function peek($index = 0, $limit = 20)
 {
     $it = new \InfiniteIterator(new \ArrayIterator($this->queues));
     $envelopes = $drained = $indexes = [];
     foreach (array_keys($this->queues) as $name) {
         $indexes[$name] = 0;
     }
     $shift = 0;
     $key = key($this->queues);
     for ($it->rewind(); $it->key() != $key; $it->next()) {
         // noop
     }
     while (count($envelopes) < $limit && count($drained) < $it->count()) {
         $queue = $it->current();
         $name = $it->key();
         if ($peeked = $queue->peek($indexes[$name], 1)) {
             if ($shift < $index) {
                 $shift++;
                 $indexes[$name]++;
             } else {
                 $envelopes[] = array_shift($peeked);
             }
         } else {
             $drained[$name] = true;
         }
         $it->next();
     }
     return $envelopes;
 }
 public function __construct($seed, callable $unaryOperator)
 {
     $this->unaryOperator = $unaryOperator;
     $this->current = $seed;
     $this->key = 0;
     parent::__construct(new \ArrayIterator([$seed]));
 }
Example #3
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $generator = $this->container->get('faker.generator');
     /** @var \FilesystemIterator $iterator */
     $dir = $this->container->getParameter('kernel.root_dir') . '/../web/images/';
     $iterator = new \InfiniteIterator(new \FilesystemIterator($dir, \FilesystemIterator::SKIP_DOTS));
     for ($i = 0; $i < 200; $i++) {
         /** @var Category $category */
         $category = $this->getReference('category_' . mt_rand(1, LoadCategoryData::COUNT));
         $product = new Product(new UuidIdentity(Uuid::uuid4()), $generator->company . ' ' . $generator->words(2, true), new Money($generator->randomNumber(4)), $category, $generator->text(500), $generator->boolean(90), '/images/' . $iterator->getFilename());
         $iterator->next();
         $opts = array_rand(range(1, LoadOptionData::COUNT), mt_rand(2, 5));
         foreach ($opts as $opt) {
             /** @var Option $option */
             $option = $this->getReference('option_' . ($opt + 1));
             $product->addOption($option, $generator->words(2, true));
         }
         $manager->persist($product);
     }
     $manager->flush();
 }
<?php

$data = array('Mela', 'Pera', 'Kiwi');
$iterator = new InfiniteIterator(new ArrayIterator($data));
foreach ($iterator as $value) {
    echo $iterator->current();
}