当前位置: 首页>>代码示例>>PHP>>正文


PHP Generator::randomElements方法代码示例

本文整理汇总了PHP中Faker\Generator::randomElements方法的典型用法代码示例。如果您正苦于以下问题:PHP Generator::randomElements方法的具体用法?PHP Generator::randomElements怎么用?PHP Generator::randomElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Faker\Generator的用法示例。


在下文中一共展示了Generator::randomElements方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 /**
  * {@inheritdoc}
  */
 public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null)
 {
     $this->familiesFile = $outputDir . '/' . self::FAMILIES_FILENAME;
     $this->delimiter = $config['delimiter'];
     $count = (int) $config['count'];
     $attributesCount = (int) $config['attributes_count'] - 1;
     $requirementsCount = (int) $config['requirements_count'] - 1;
     $this->identifierAttribute = $config['identifier_attribute'];
     $this->labelAttribute = $config['label_attribute'];
     $this->faker = Faker\Factory::create();
     $families = [];
     for ($i = 0; $i < $count; $i++) {
         $family = [];
         $family['code'] = self::FAMILY_CODE_PREFIX . $i;
         foreach ($this->getLocalizedRandomLabels() as $localeCode => $label) {
             $family['label-' . $localeCode] = $label;
         }
         $family['attribute_as_label'] = $this->labelAttribute;
         $attributes = $this->faker->randomElements($this->getAttributeCodes(), $attributesCount);
         $attributes = array_unique(array_merge([$this->identifierAttribute, $this->labelAttribute], $attributes));
         $family['attributes'] = implode(static::ATTRIBUTE_DELIMITER, $attributes);
         $requirements = [];
         foreach ($this->getChannels() as $channel) {
             $attributeReqs = $this->faker->randomElements($this->getAttributeCodes(), $requirementsCount);
             $attributeReqs = array_merge([$this->identifierAttribute], $attributeReqs);
             $family['requirements-' . $channel->getCode()] = implode(static::ATTRIBUTE_DELIMITER, $attributeReqs);
         }
         $families[$family['code']] = $family;
         $progress->advance();
     }
     $this->families = $families;
     $headers = $this->getAllKeys($this->families);
     $this->writeCsvFile($this->families, $headers);
     return $this;
 }
开发者ID:norfil,项目名称:DataGeneratorBundle,代码行数:38,代码来源:FamilyGenerator.php

示例2: getRandomJob

 /**
  * Returns a random active job
  *
  * @return mixed
  */
 protected function getRandomJob($department = null)
 {
     $jobs = \App\Models\JobCard::active()->lists('job_cards_id')->toArray();
     if ($department == 'printing') {
         $jobs = \App\Models\JobCard::active()->printingCurrentTen()->lists('job_cards_id')->toArray();
     }
     $randomJob = \App\Models\JobCard::find($this->fake->randomElements($jobs))[0];
     return $randomJob;
 }
开发者ID:buys-fran,项目名称:mtech-mis,代码行数:14,代码来源:MisAcceptanceTestCase.php

示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = $this->userRepository->findAll();
     $tags = Tag::get(['id'])->pluck('id')->toArray();
     for ($i = 0; $i < 20; $i++) {
         $user = $users->random();
         $count = mt_rand(1, 2);
         $post = Post::instantiate($user, ['title' => $user->name . '的好贴'], $this->faker->randomElements($tags, $count));
         Comment::instantiate($user, $post, ['body' => $this->faker->text, 'views' => $this->faker->numberBetween(0, 1000)]);
     }
     Post::inRandomOrder()->first()->makeSticky();
 }
开发者ID:gez-studio,项目名称:gez-mall,代码行数:17,代码来源:PostSeeder.php

示例4: generate

 public function generate($databaseName, $size, $batchSize = 1000)
 {
     $this->getConnection()->query(sprintf('USE %s', $databaseName));
     $this->reset();
     $scopes = array_keys($this->scopeFaker);
     $numberOfScopes = count($scopes);
     $currentBatch = 0;
     $createdRecords = 0;
     while ($size > $createdRecords) {
         if ($currentBatch >= $batchSize) {
             $this->flush();
             $currentBatch = 0;
         }
         $createdRecords++;
         $currentBatch++;
         $code = $this->faker->uuid;
         $this->batch['entity'][$code] = ['code' => $code];
         $this->generateAttributes($this->faker, $this->attribute->getAll(), $code, 0);
         if ($this->faker->boolean(66)) {
             $currentScopes = $this->faker->randomElements($scopes, $this->faker->numberBetween(1, $numberOfScopes));
             foreach ($currentScopes as $scopeCode) {
                 $this->generateAttributes($this->scopeFaker[$scopeCode], $this->attribute->getAllScopeAware(), $code, $this->scope->getId($scopeCode));
             }
         }
     }
     if ($currentBatch > 0) {
         $this->flush();
     }
     return $this;
 }
开发者ID:EcomDev,项目名称:mysql-performance-benchmark,代码行数:30,代码来源:Generator.php

示例5: test

 public function test(TestCase $test, Generator $faker)
 {
     $values = array_filter(array_keys($this->items), function ($value) {
         return !!$value;
     });
     if (count($values)) {
         $test->select($faker->randomElements($values), "{$this->name}");
     }
     return true;
 }
开发者ID:smallhadroncollider,项目名称:laravel-form-presenter,代码行数:10,代码来源:MultiSelect.php

示例6: getAssociatedProductsAsArray

 /**
  * @param ProductInterface $owner
  *
  * @return string[]
  */
 private function getAssociatedProductsAsArray(ProductInterface $owner)
 {
     $products = $this->productRepository->findBy(['mainTaxon' => $owner->getMainTaxon()]);
     $products = $this->faker->randomElements($products, 3);
     $associatedProducts = [];
     /** @var ProductInterface $product */
     foreach ($products as $product) {
         $associatedProducts[] = $product->getCode();
     }
     return $associatedProducts;
 }
开发者ID:NeverResponse,项目名称:Sylius,代码行数:16,代码来源:SimilarProductAssociationFixture.php

示例7: createPaths

 /**
  * @param int $count
  * @param Video[] $videos
  * @param User[] $users
  * @param PathsRepository $paths
  */
 private function createPaths($count, array $videos, array $users, PathsRepository $paths)
 {
     $this->out->writeln(Path::class);
     /** @var ProgressHelper $progress */
     $progress = $this->getHelperSet()->get('progress');
     $progress->start($this->out, $count);
     for ($i = 0; $i < $count; ++$i) {
         $path = new Path();
         $path->author = $this->faker->randomElement($users);
         $path->setList($this->faker->randomElements($videos, 7));
         $progress->advance();
         $paths->attach($path);
     }
     $progress->finish();
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:21,代码来源:Fake.php

示例8: getRandomCategoryCodes

 /**
  * Get random categories
  *
  * @param int $count
  *
  * @return array
  */
 protected function getRandomCategoryCodes($count)
 {
     return $this->faker->randomElements($this->getCategoryCodes(), $count);
 }
开发者ID:norfil,项目名称:DataGeneratorBundle,代码行数:11,代码来源:ProductGenerator.php

示例9: getRandomActiveJob

 private function getRandomActiveJob()
 {
     $this->jobs = App\Models\JobCard::active()->lists('job_cards_id')->toArray();
     return App\Models\JobCard::find($this->fake->randomElements($this->jobs))[0];
 }
开发者ID:buys-fran,项目名称:mtech-mis,代码行数:5,代码来源:JobCardModelTest.php

示例10: getMediaProperties

 /**
  * Provide media specific properties
  *
  * @return array
  */
 protected function getMediaProperties()
 {
     return ['allowed_extensions' => implode(',', $this->faker->randomElements(['png', 'jpg', 'pdf'], 2))];
 }
开发者ID:norfil,项目名称:DataGeneratorBundle,代码行数:9,代码来源:AttributeGenerator.php

示例11: getRandomAttributesFromFamily

 /**
  * Get a random attribute from the family
  *
  * @param Family $family
  *,@param int    $count
  *
  * @return array
  */
 protected function getRandomAttributesFromFamily(Family $family, $count)
 {
     return $this->faker->randomElements($this->getAttributesFromFamily($family), $count);
 }
开发者ID:norfil,项目名称:DataGeneratorBundle,代码行数:12,代码来源:AssociationCsvGenerator.php


注:本文中的Faker\Generator::randomElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。