本文整理汇总了PHP中Faker\Generator::sentence方法的典型用法代码示例。如果您正苦于以下问题:PHP Generator::sentence方法的具体用法?PHP Generator::sentence怎么用?PHP Generator::sentence使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Faker\Generator
的用法示例。
在下文中一共展示了Generator::sentence方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLocalizedRandomLabels
/**
* Get localized random labels
*
* @return array
*/
protected function getLocalizedRandomLabels()
{
$locales = $this->getLocales();
$labels = [];
foreach ($locales as $locale) {
$labels[$locale->getCode()] = $this->faker->sentence(2);
}
return $labels;
}
示例2: testSave
/**
* @covers \Glue\Storage\Blob::save
*/
public function testSave()
{
$data = $this->faker->sentence();
$result = $this->blob->save($data);
$this->assertNotEquals(false, $result);
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('0', $result);
$this->assertArrayHasKey('1', $result);
$this->assertEquals(strlen($data), $result[1]);
}
示例3: __construct
/**
* @param FactoryInterface $paymentMethodFactory
* @param RepositoryInterface $localeRepository
*/
public function __construct(FactoryInterface $paymentMethodFactory, RepositoryInterface $localeRepository)
{
$this->paymentMethodFactory = $paymentMethodFactory;
$this->localeRepository = $localeRepository;
$this->faker = \Faker\Factory::create();
$this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) {
return $this->faker->words(3, true);
})->setDefault('code', function (Options $options) {
return StringInflector::nameToCode($options['name']);
})->setDefault('description', function (Options $options) {
return $this->faker->sentence();
})->setDefault('gateway', 'offline')->setDefault('enabled', function (Options $options) {
return $this->faker->boolean(90);
})->setAllowedTypes('enabled', 'bool');
}
示例4: __construct
/**
* @param FactoryInterface $shippingMethodFactory
* @param RepositoryInterface $zoneRepository
* @param RepositoryInterface $shippingCategoryRepository
* @param RepositoryInterface $localeRepository
*/
public function __construct(FactoryInterface $shippingMethodFactory, RepositoryInterface $zoneRepository, RepositoryInterface $shippingCategoryRepository, RepositoryInterface $localeRepository)
{
$this->shippingMethodFactory = $shippingMethodFactory;
$this->localeRepository = $localeRepository;
$this->faker = \Faker\Factory::create();
$this->optionsResolver = (new OptionsResolver())->setDefault('code', function (Options $options) {
return StringInflector::nameToCode($options['name']);
})->setDefault('name', function (Options $options) {
return $this->faker->words(3, true);
})->setDefault('description', function (Options $options) {
return $this->faker->sentence();
})->setDefault('enabled', function (Options $options) {
return $this->faker->boolean(90);
})->setAllowedTypes('enabled', 'bool')->setDefault('zone', LazyOption::randomOne($zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($zoneRepository, 'code'))->setDefined('shipping_category')->setAllowedTypes('shipping_category', ['null', 'string', ShippingCategoryInterface::class])->setNormalizer('shipping_category', LazyOption::findOneBy($shippingCategoryRepository, 'code'))->setDefault('calculator', function (Options $options) {
return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => ['amount' => $this->faker->randomNumber(4)]];
});
}
示例5: generateValueData
/**
* Generate value content based on backend type
*
* @param AbstractAttribute $attribute
* @param string $key
*
* @return string
*/
protected function generateValueData(AbstractAttribute $attribute, $key)
{
$data = "";
if (isset($this->forcedValues[$attribute->getCode()])) {
return $this->forcedValues[$attribute->getCode()];
}
switch ($attribute->getBackendType()) {
case "varchar":
$validationRule = $attribute->getValidationRule();
switch ($validationRule) {
case 'url':
$data = $this->faker->url();
break;
default:
$data = $this->faker->sentence();
break;
}
break;
case "text":
$data = $this->faker->sentence();
break;
case "date":
$data = $this->faker->dateTimeBetween($attribute->getDateMin(), $attribute->getDateMax());
$data = $data->format('Y-m-d');
break;
case "metric":
case "decimal":
case "prices":
if ($attribute->getBackendType() && preg_match('/-' . self::METRIC_UNIT . '$/', $key)) {
$data = $attribute->getDefaultMetricUnit();
} else {
$min = $attribute->getNumberMin() != null ? $attribute->getNumberMin() : self::DEFAULT_NUMBER_MIN;
$max = $attribute->getNumberMax() != null ? $attribute->getNumberMax() : self::DEFAULT_NUMBER_MAX;
$decimals = $attribute->isDecimalsAllowed() ? self::DEFAULT_NB_DECIMALS : 0;
$data = $this->faker->randomFloat($decimals, $min, $max);
}
break;
case "boolean":
$data = $this->faker->boolean() ? "1" : "0";
break;
case "option":
case "options":
$options = [];
foreach ($attribute->getOptions() as $option) {
$options[] = $option;
}
$option = $this->faker->randomElement($options);
if (is_object($option)) {
$data = $option->getCode();
}
break;
default:
$data = '';
break;
}
return (string) $data;
}
示例6: configureOptions
/**
* {@inheritdoc}
*/
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('name', function (Options $options) {
return $this->faker->words(3, true);
})->setDefault('code', function (Options $options) {
return StringInflector::nameToCode($options['name']);
})->setDefault('description', function (Options $options) {
return $this->faker->sentence();
})->setDefault('gateway', 'offline')->setDefault('enabled', function (Options $options) {
return $this->faker->boolean(90);
})->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setAllowedTypes('enabled', 'bool');
}
示例7: load
public function load(ObjectManager $manager)
{
$faker = new Faker\Generator();
$faker->addProvider(new Faker\Provider\en_US\Text($faker));
$faker->addProvider(new Faker\Provider\Lorem($faker));
for ($i = 1; $i <= 100; $i++) {
$post = new Post();
$post->setTitle($faker->sentence(4));
$post->setBody($faker->realText(500));
$manager->persist($post);
}
$manager->flush();
}
示例8: resolveConfigType
private function resolveConfigType($config)
{
switch ($config['type']) {
case "url":
return $this->faker->url;
case "image":
$width = isset($config['options']['width']) ? $config['options']['width'] : 800;
$height = isset($config['options']['height']) ? $config['options']['height'] : 400;
return $this->faker->imageUrl($width, $height);
case "page_select":
$page = ['title' => $this->faker->sentence(), 'body' => $this->faker->text(6000), 'slug' => $this->faker->slug, 'created' => $this->faker->date()];
return $page;
case "product_category_select":
case "collection_select":
$category = ["name" => $this->faker->word, "slug" => $this->faker->slug];
return $category;
case "product_select":
return $this->tdk->makeProduct();
default:
return $this->faker->word;
}
}
示例9: configureOptions
/**
* {@inheritdoc}
*/
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('code', function (Options $options) {
return StringInflector::nameToCode($options['name']);
})->setDefault('name', $this->faker->words(3, true))->setDefault('description', $this->faker->sentence())->setDefault('usage_limit', null)->setDefault('coupon_based', false)->setDefault('exclusive', $this->faker->boolean(25))->setDefault('priority', 0)->setDefault('starts_at', null)->setAllowedTypes('starts_at', ['null', 'string'])->setDefault('ends_at', null)->setAllowedTypes('ends_at', ['null', 'string'])->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setDefined('rules')->setNormalizer('rules', function (Options $options, array $rules) {
if (empty($rules)) {
return [[]];
}
return $rules;
})->setDefined('actions')->setNormalizer('actions', function (Options $options, array $actions) {
if (empty($actions)) {
return [[]];
}
return $actions;
});
}
示例10: configureOptions
/**
* {@inheritdoc}
*/
protected function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('code', function (Options $options) {
return StringInflector::nameToCode($options['name']);
})->setDefault('name', function (Options $options) {
return $this->faker->words(3, true);
})->setDefault('description', function (Options $options) {
return $this->faker->sentence();
})->setDefault('enabled', function (Options $options) {
return $this->faker->boolean(90);
})->setAllowedTypes('enabled', 'bool')->setDefault('zone', LazyOption::randomOne($this->zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($this->zoneRepository, 'code'))->setDefined('shipping_category')->setAllowedTypes('shipping_category', ['null', 'string', ShippingCategoryInterface::class])->setNormalizer('shipping_category', LazyOption::findOneBy($this->shippingCategoryRepository, 'code'))->setDefault('calculator', function (Options $options) {
$configuration = [];
/** @var ChannelInterface $channel */
foreach ($options['channels'] as $channel) {
$configuration[$channel->getCode()] = ['amount' => $this->faker->randomNumber(4)];
}
return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => $configuration];
})->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'));
}
示例11: getDummyData
public function getDummyData(Generator $faker, array $customValues = array())
{
return ['title' => $faker->sentence(), 'status' => $faker->randomElement(['open', 'open', 'closed']), 'user_id' => $this->getRandom('User')->id];
}
示例12: getDummyData
public function getDummyData(Generator $faker)
{
return ["title" => $faker->sentence(), "status" => $faker->randomElement(["open", "closed"]), "user_id" => $this->getRandomId("User")];
}
示例13: getSentence
/**
* @param int $wordCount
* @return string
*/
public function getSentence($wordCount)
{
return $this->faker->sentence(max($wordCount, 1));
}
示例14: getDummyData
public function getDummyData(Generator $faker, array $valoresPersonalizados = array())
{
return ['titulo' => $faker->sentence(), 'estado' => $faker->randomElement(['abierto', 'cerrado']), 'user_id' => $this->getRandom('User')->id];
}
示例15: newApiRequest
/**
* @param string $endpoint
* @return RequestInterface
*/
private function newApiRequest($endpoint)
{
$request = (new Request($endpoint))->withMethod('POST')->withHeader('Content-Type', 'application/x-www-form-urlencoded');
$request->getBody()->write(http_build_query(['data' => $this->faker->sentence(rand(3, 6))]));
return $request;
}