|
| 1 | +] |
| 2 | +[](https://packagist.org/packages/pattern-lab/plugin-faker) [](https://gitter.im/pattern-lab/php) |
| 3 | + |
1 | 4 | # Faker Plugin for Pattern Lab
|
2 | 5 |
|
3 |
| -The Faker Plugin adds support for the [Faker Library](https://github.com/fzaninotto/Faker) to Pattern Lab. |
| 6 | +The Faker Plugin adds [Faker](https://github.com/fzaninotto/Faker) support to Pattern Lab. The Faker Plugin will create unique content each time Pattern Lab is generated. You can also use the Faker Plugin to provide locale appropriate content. |
4 | 7 |
|
5 | 8 | ## Installation
|
6 | 9 |
|
7 |
| -Pattern Lab PHP uses [Composer](https://getcomposer.org/) to manage project dependencies with Pattern Lab Editions. To add the Faker Plugin to the dependencies list for your Edition you can type the following in the command line at the base of your project: |
| 10 | +To add the Faker Plugin to your project using [Composer](https://getcomposer.org/) type: |
8 | 11 |
|
9 | 12 | composer require pattern-lab/plugin-faker
|
10 | 13 |
|
11 | 14 | See Packagist for [information on the latest release](https://packagist.org/packages/pattern-lab/plugin-faker).
|
12 | 15 |
|
13 | 16 | ## Usage
|
14 | 17 |
|
15 |
| -To use this in your project set the value for a data option to: |
| 18 | +You can create fake data in your `json` or `yml` data files by using this format: |
| 19 | + |
| 20 | + "key": "Faker.[formatter]([options])" |
| 21 | + |
| 22 | +If a formatter has no options or you want to use the formatter's default options you can use the following format: |
| 23 | + |
| 24 | + "key": "Faker.[formatter]" |
| 25 | + |
| 26 | +See below for a list of formatters and their options. |
| 27 | + |
| 28 | +## Example |
| 29 | + |
| 30 | +To create a random first name without regard to gender you can add the following to your `json` or `yml` data files: |
| 31 | + |
| 32 | + "firstName": "Faker.firstName" |
| 33 | + |
| 34 | +To specify a gender you would use: |
| 35 | + |
| 36 | + "firstName": "Faker.firstName('female')" |
| 37 | + |
| 38 | +## Formatters |
| 39 | + |
| 40 | +The Faker Plugin supports the following content formatters: |
| 41 | + |
| 42 | +* Faker\Provider\en_US\Person |
| 43 | +* Faker\Provider\en_US\Address |
| 44 | +* Faker\Provider\en_US\PhoneNumber |
| 45 | +* Faker\Provider\en_US\Company |
| 46 | +* Faker\Provider\Lorem |
| 47 | +* Faker\Provider\Internet |
| 48 | +* Faker\Provider\Color |
| 49 | +* Faker\Provider\Payment |
| 50 | +* Faker\Provider\DateTime |
| 51 | +* Faker\Provider\Image |
| 52 | +* Faker\Provider\Miscellaneous |
| 53 | + |
| 54 | +See the official repository for a [list of options available to each formatter](https://github.com/fzaninotto/Faker#formatters). |
| 55 | + |
| 56 | +## Locales |
| 57 | + |
| 58 | +The content produced by Faker can be localized based on a Faker locale. If the Faker locale isn't supported by a formatter the content will fall back to the default `en_US`. There is a [list of Faker locales](https://github.com/fzaninotto/Faker/tree/master/src/Faker/Provider). |
16 | 59 |
|
17 |
| -``` |
18 |
| -"key": "Faker.[formatter]([options])", |
19 |
| -``` |
| 60 | +To update your Faker locale you can either directly edit `./config/config.yml` or use the command line option: |
20 | 61 |
|
21 |
| -For example, to have a random first name use: |
| 62 | + php core/console --config --set faker.locale=[locale] |
22 | 63 |
|
23 |
| -``` |
24 |
| -"firstName": "Faker.firstName('female')", |
25 |
| -``` |
| 64 | +For example: |
26 | 65 |
|
27 |
| -Using Mustache as an example you'd use: |
| 66 | + php core/console --config --set faker.locale=fr_FR |
28 | 67 |
|
29 |
| -``` |
30 |
| -First Name: {{ firstName }} |
31 |
| -``` |
| 68 | +## Disabling the Plugin |
32 | 69 |
|
33 |
| -would output: |
| 70 | +To disable the Faker plugin you can either directly edit `./config/config.yml` or use the command line option: |
34 | 71 |
|
35 |
| -``` |
36 |
| -First Name: Mary |
37 |
| -``` |
| 72 | + php core/console --config --set faker.on=false |
0 commit comments