r1pp3rj4ck / lipsum-bundle
r1pp3rj4ck LipsumBundle
v1.0.1
2014-07-17 13:09 UTC
Requires
- php: >5.3.2
- symfony/framework-bundle: >=2.1
This package is not auto-updated.
Last update: 2024-09-14 13:13:17 UTC
README
生成用于固定和其他用途的垃圾内容
许可证
此包附带MIT许可证。完整许可证在此处提供
安装
步骤 1: 使用Composer下载r1pp3rj4ckLipsumBundle
将r1pp3rj4ckLipsumBundle添加到您的composer.json文件中
{ "require": { "r1pp3rj4ck/lipsum-bundle": "dev-master" } }
更新您的供应商
$ php composer.phar update
或者您也可以仅安装r1pp3rj4ckLipsumBundle
$ php composer.phar update r1pp3rj4ck/lipsum-bundle
步骤 2: 在您的内核中注册该包
您不应该有在生产环境中使用此包的理由,所以您只需在开发环境中注册即可
<?php // app/AppKernel.php if (in_array($this->getEnvironment(), array('dev', 'test'))) { // ... $bundles[] = new r1pp3rj4ck\LipsumBundle\r1pp3rj4ckLipsumBundle(); // ... }
(可选) 步骤 3: 更改固定文件
此包附带三个包含1,219个男性姓名、1,000个女性姓名和1,000个姓氏的固定文件。您可以在配置中覆盖这些默认文件(例如,对于您本地语言的常用姓名)
文件必须每行包含一个名称。
# app/config_dev.yml r1pp3rj4ck_lipsum: generator: profile: male_names: src/Acme/DemoBundle/DataFixtures/male_names.txt female_names: src/Acme/DemoBundle/DataFixtures/female_names.txt last_names: src/Acme/DemoBundle/DataFixtures/last_names.txt
(可选) 步骤 4: 覆盖默认生成器
您可以通过实现 r1pp3rj4ck\LipsumBundle\Generator\GeneratorInterface
接口并将其添加到配置中来覆盖默认生成器
# app/config_dev.yml r1pp3rj4ck_lipsum: generator: class: Acme\DemoBundle\Generator\Generator
服务
r1pp3rj4ck.lipsum.generator.profile
- 生成用户数据
使用方法
<?php $profileGenerator = $this->container->get('r1pp3rj4ck.lipsum.generator.profile'); $userData = $profileGenerator->getUserData(ProfileGenerator::SEX_RANDOM); $refUserData = array( 'fullName' => 'John Doe', 'firstName' => 'John', 'middleName' => '', 'lastName' => 'Doe', 'userName' => 'john.doe314', 'email' => 'john.doe314@gmail.com', ); // $userData and $refUserData will look like the same but with another data // ProfileGenerator::getUserData($sex = ProfileGenerator::SEX_RANDOM); // possible $sex values: SEX_RANDOM, SEX_MALE, SEX_FEMALE $name = $profileGenerator->getName(ProfileGenerator::SEX_FEMALE, false) $refName = array( 'fullName' => 'Jane Doe', 'firstName' => 'Jane', 'middleName' => '', 'lastName' => 'Doe', ); // $name and $refName will look like the same but with another data // ProfileGenerator::getName($sex = ProfileGenerator::SEX_RANDOM, $middleName = false) $firstName = $profileGenerator->getFirstName(ProfileGenerator::SEX_MALE); $refFirstName = 'John'; $name = 'Jane Mary Doe'; $userName = $profileGenerator->getUserName($name); $refUserName = 'jane.mary.doe813'; $email = $profileGenerator->getEmail($userName); $refEmail = 'jane.mary.doe813@gmail.com';
r1pp3rj4ck.lipsum.generator.random
- 生成随机字符串
使用方法
<?php $randomGenerator = $this->container->get('r1pp3rj4ck.lipsum.generator.random'); $lipsum = $randomGenerator->getRandom(42, RandomGenerator::PUNCTUATION_ON); // $lipsum will be a 42 words long string, containing punctuation randomly, // always with a dot on the end. // possible punctuation values: // PUNCTUATION_NONE - no punctuation at all // PUNCTUATION_AT_END - a dot at the end of string, nowhere else // PUNCTUATION_ON - (default) contains punctuation randomly + a dot at the end
r1pp3rj4ck.lipsum.generator.address
- 生成随机地址
使用方法
<?php $addressGenerator = $this->container->get('r1pp3rj4ck.lipsum.generator.address'); $address = $addressGenerator->getStreetName(); // $address == 'Holly Drive' $address = $addressGenerator->getAddress(); // $address == array( // 'streetName' => 'Holly Drive', // 'streetNumber' => 242, // 'fullAddress' => 'Holly Drive 242', // );
配置参考
此配置参考包含所有内容的默认值
# app/config_dev.yml r1pp3rj4ck_lipsum: generator: profile: male_names: vendor/r1pp3rj4ck/lipsum-bundle/data/malenames.txt female_names: vendor/r1pp3rj4ck/lipsum-bundle/data/femalenames.txt last_names: vendor/r1pp3rj4ck/lipsum-bundle/data/lastnames.txt class: r1pp3rj4ck\LipsumBundle\Generator\ProfileGenerator random: random: vendor/r1pp3rj4ck/lipsum-bundle/data/lipsum.txt class: r1pp3rj4ck\LipsumBundle\Generator\RandomGenerator address: street_names: vendor/r1pp3rj4ck/lipsum-bundle/data/streetnames.txt class: r1pp3rj4ck\LipsumBundle\Generator\AddressGenerator