本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例8: getRandomCategoryCodes
/**
* Get random categories
*
* @param int $count
*
* @return array
*/
protected function getRandomCategoryCodes($count)
{
return $this->faker->randomElements($this->getCategoryCodes(), $count);
}
示例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];
}
示例10: getMediaProperties
/**
* Provide media specific properties
*
* @return array
*/
protected function getMediaProperties()
{
return ['allowed_extensions' => implode(',', $this->faker->randomElements(['png', 'jpg', 'pdf'], 2))];
}
示例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);
}