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


PHP Generator::optional方法代码示例

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


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

示例1: createComments

 /**
  * @param int $count
  * @param Video[] $videos
  * @param User[] $users
  * @param Repository $repo
  * @throws \Exception
  */
 protected function createComments($count, $videos, $users, Repository $repo)
 {
     $this->out->writeln(Comment::class);
     /** @var ProgressHelper $progress */
     $progress = $this->getHelperSet()->get('progress');
     $progress->start($this->out, count($videos) * $count);
     foreach ($videos as $video) {
         $comments = [];
         for ($i = 0; $i < $count; ++$i) {
             $comment = new Comment();
             $comment->author = $this->faker->randomElement($users);
             $comment->text = $this->faker->realText(100);
             $comment->inReplyTo = $this->faker->optional(0.25)->randomElement($comments);
             $video->comments->add($comment);
             $comments[] = $comment;
             $progress->advance();
         }
         $repo->persist($video);
     }
     $progress->finish();
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:28,代码来源:Fake.php

示例2: createRubrics

 private function createRubrics($count = 50)
 {
     print_r("Create rubrics. Count: " . $count . "...");
     $this->faker->unique(true);
     for ($i = 1; $i <= $count; $i++) {
         $rubric = new Rubric();
         $rubric->title = ucfirst($this->faker->word);
         if ($i === 1) {
             $parent_id = NULL;
         } else {
             do {
                 $parent_id = $this->faker->optional(0.7)->numberBetween(1, $i);
             } while ($parent_id === $i);
         }
         $rubric->parent_id = $parent_id;
         $rubric->save();
     }
     print_r("DONE" . PHP_EOL);
 }
开发者ID:novikovsergey,项目名称:doublegis,代码行数:19,代码来源:GeneratorController.php

示例3: generateAttributes

 private function generateAttributes(FakerGenerator $faker, $attributes, $code, $scopeId)
 {
     foreach ($attributes as $attribute) {
         $attributeFaker = $faker;
         if (1 - $attribute->required > 0.001) {
             $attributeFaker = $faker->optional($attribute->required);
         }
         $value = $attributeFaker->format($attribute->generatorMethod, $attribute->generatorArguments);
         if ($value !== null) {
             if ($value instanceof \DateTime) {
                 $value = $value->format('Y-m-d H:i:s');
             }
             $valueKey = sprintf('%s-%s-%s', $code, $attribute->id, $scopeId);
             $this->batch['value'][$attribute->type][$valueKey] = ['entity_id' => null, 'attribute_id' => $attribute->id, 'scope_id' => $scopeId, 'value' => $value];
             $this->batch['value_index'][$code][] = [$attribute->type, $valueKey];
         }
     }
     return $this;
 }
开发者ID:EcomDev,项目名称:mysql-performance-benchmark,代码行数:19,代码来源:Generator.php


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