Beispiel #1
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();
 }