Projekt

Obecné

Profil

Stáhnout (52.9 KB) Statistiky
| Větev: | Revize:
1
# Faker
2

    
3
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
4

    
5
Faker is heavily inspired by Perl's [Data::Faker](http://search.cpan.org/~jasonk/Data-Faker-0.07/), and by ruby's [Faker](https://rubygems.org/gems/faker).
6

    
7
Faker requires PHP >= 5.3.3.
8

    
9
[![Monthly Downloads](https://poser.pugx.org/fzaninotto/faker/d/monthly.png)](https://packagist.org/packages/fzaninotto/faker) [![Build Status](https://travis-ci.org/fzaninotto/Faker.svg?branch=master)](https://travis-ci.org/fzaninotto/Faker) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/eceb78a9-38d4-4ad5-8b6b-b52f323e3549/mini.png)](https://insight.sensiolabs.com/projects/eceb78a9-38d4-4ad5-8b6b-b52f323e3549)
10

    
11
# Table of Contents
12

    
13
- [Installation](#installation)
14
- [Basic Usage](#basic-usage)
15
- [Formatters](#formatters)
16
	- [Base](#fakerproviderbase)
17
	- [Lorem Ipsum Text](#fakerproviderlorem)
18
	- [Person](#fakerprovideren_usperson)
19
	- [Address](#fakerprovideren_usaddress)
20
	- [Phone Number](#fakerprovideren_usphonenumber)
21
	- [Company](#fakerprovideren_uscompany)
22
	- [Real Text](#fakerprovideren_ustext)
23
	- [Date and Time](#fakerproviderdatetime)
24
	- [Internet](#fakerproviderinternet)
25
	- [User Agent](#fakerprovideruseragent)
26
	- [Payment](#fakerproviderpayment)
27
	- [Color](#fakerprovidercolor)
28
	- [File](#fakerproviderfile)
29
	- [Image](#fakerproviderimage)
30
	- [Uuid](#fakerprovideruuid)
31
	- [Barcode](#fakerproviderbarcode)
32
	- [Miscellaneous](#fakerprovidermiscellaneous)
33
	- [Biased](#fakerproviderbiased)
34
	- [Html Lorem](#fakerproviderhtmllorem)
35
- [Modifiers](#modifiers)
36
- [Localization](#localization)
37
- [Populating Entities Using an ORM or an ODM](#populating-entities-using-an-orm-or-an-odm)
38
- [Seeding the Generator](#seeding-the-generator)
39
- [Faker Internals: Understanding Providers](#faker-internals-understanding-providers)
40
- [Real Life Usage](#real-life-usage)
41
- [Language specific formatters](#language-specific-formatters)
42
- [Third-Party Libraries Extending/Based On Faker](#third-party-libraries-extendingbased-on-faker)
43
- [License](#license)
44

    
45

    
46
## Installation
47

    
48
```sh
49
composer require fzaninotto/faker
50
```
51

    
52
## Basic Usage
53

    
54
Use `Faker\Factory::create()` to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.
55

    
56
```php
57
<?php
58
// require the Faker autoloader
59
require_once '/path/to/Faker/src/autoload.php';
60
// alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader for instance)
61

    
62
// use the factory to create a Faker\Generator instance
63
$faker = Faker\Factory::create();
64

    
65
// generate data by accessing properties
66
echo $faker->name;
67
  // 'Lucy Cechtelar';
68
echo $faker->address;
69
  // "426 Jordy Lodge
70
  // Cartwrightshire, SC 88120-6700"
71
echo $faker->text;
72
  // Dolores sit sint laboriosam dolorem culpa et autem. Beatae nam sunt fugit
73
  // et sit et mollitia sed.
74
  // Fuga deserunt tempora facere magni omnis. Omnis quia temporibus laudantium
75
  // sit minima sint.
76
```
77

    
78
Even if this example shows a property access, each call to `$faker->name` yields a different (random) result. This is because Faker uses `__get()` magic, and forwards `Faker\Generator->$property` calls to `Faker\Generator->format($property)`.
79

    
80
```php
81
<?php
82
for ($i=0; $i < 10; $i++) {
83
  echo $faker->name, "\n";
84
}
85
  // Adaline Reichel
86
  // Dr. Santa Prosacco DVM
87
  // Noemy Vandervort V
88
  // Lexi O'Conner
89
  // Gracie Weber
90
  // Roscoe Johns
91
  // Emmett Lebsack
92
  // Keegan Thiel
93
  // Wellington Koelpin II
94
  // Ms. Karley Kiehn V
95
```
96

    
97
**Tip**: For a quick generation of fake data, you can also use Faker as a command line tool thanks to [faker-cli](https://github.com/bit3/faker-cli).
98

    
99
## Formatters
100

    
101
Each of the generator properties (like `name`, `address`, and `lorem`) are called "formatters". A faker generator has many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale.
102

    
103
### `Faker\Provider\Base`
104

    
105
    randomDigit             // 7
106
    randomDigitNotNull      // 5
107
    randomNumber($nbDigits = NULL, $strict = false) // 79907610
108
    randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932
109
    numberBetween($min = 1000, $max = 9000) // 8567
110
    randomLetter            // 'b'
111
    // returns randomly ordered subsequence of a provided array
112
    randomElements($array = array ('a','b','c'), $count = 1) // array('c')
113
    randomElement($array = array ('a','b','c')) // 'b'
114
    shuffle('hello, world') // 'rlo,h eoldlw'
115
    shuffle(array(1, 2, 3)) // array(2, 1, 3)
116
    numerify('Hello ###') // 'Hello 609'
117
    lexify('Hello ???') // 'Hello wgt'
118
    bothify('Hello ##??') // 'Hello 42jz'
119
    asciify('Hello ***') // 'Hello R6+'
120
    regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej
121

    
122
### `Faker\Provider\Lorem`
123

    
124
    word                                             // 'aut'
125
    words($nb = 3, $asText = false)                  // array('porro', 'sed', 'magni')
126
    sentence($nbWords = 6, $variableNbWords = true)  // 'Sit vitae voluptas sint non voluptates.'
127
    sentences($nb = 3, $asText = false)              // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.')
128
    paragraph($nbSentences = 3, $variableNbSentences = true) // 'Ut ab voluptas sed a nam. Sint autem inventore aut officia aut aut blanditiis. Ducimus eos odit amet et est ut eum.'
129
    paragraphs($nb = 3, $asText = false)             // array('Quidem ut sunt et quidem est accusamus aut. Fuga est placeat rerum ut. Enim ex eveniet facere sunt.', 'Aut nam et eum architecto fugit repellendus illo. Qui ex esse veritatis.', 'Possimus omnis aut incidunt sunt. Asperiores incidunt iure sequi cum culpa rem. Rerum exercitationem est rem.')
130
    text($maxNbChars = 200)                          // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.'
131

    
132
### `Faker\Provider\en_US\Person`
133

    
134
    title($gender = null|'male'|'female')     // 'Ms.'
135
    titleMale                                 // 'Mr.'
136
    titleFemale                               // 'Ms.'
137
    suffix                                    // 'Jr.'
138
    name($gender = null|'male'|'female')      // 'Dr. Zane Stroman'
139
    firstName($gender = null|'male'|'female') // 'Maynard'
140
    firstNameMale                             // 'Maynard'
141
    firstNameFemale                           // 'Rachel'
142
    lastName                                  // 'Zulauf'
143

    
144
### `Faker\Provider\en_US\Address`
145

    
146
    cityPrefix                          // 'Lake'
147
    secondaryAddress                    // 'Suite 961'
148
    state                               // 'NewMexico'
149
    stateAbbr                           // 'OH'
150
    citySuffix                          // 'borough'
151
    streetSuffix                        // 'Keys'
152
    buildingNumber                      // '484'
153
    city                                // 'West Judge'
154
    streetName                          // 'Keegan Trail'
155
    streetAddress                       // '439 Karley Loaf Suite 897'
156
    postcode                            // '17916'
157
    address                             // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
158
    country                             // 'Falkland Islands (Malvinas)'
159
    latitude($min = -90, $max = 90)     // 77.147489
160
    longitude($min = -180, $max = 180)  // 86.211205
161

    
162
### `Faker\Provider\en_US\PhoneNumber`
163

    
164
    phoneNumber             // '201-886-0269 x3767'
165
    tollFreePhoneNumber     // '(888) 937-7238'
166
    e164PhoneNumber     // '+27113456789'
167

    
168
### `Faker\Provider\en_US\Company`
169

    
170
    catchPhrase             // 'Monitored regional contingency'
171
    bs                      // 'e-enable robust architectures'
172
    company                 // 'Bogan-Treutel'
173
    companySuffix           // 'and Sons'
174
    jobTitle                // 'Cashier'
175

    
176
### `Faker\Provider\en_US\Text`
177

    
178
    realText($maxNbChars = 200, $indexSize = 2) // "And yet I wish you could manage it?) 'And what are they made of?' Alice asked in a shrill, passionate voice. 'Would YOU like cats if you were never even spoke to Time!' 'Perhaps not,' Alice replied."
179

    
180
### `Faker\Provider\DateTime`
181

    
182
    unixTime($max = 'now')                // 58781813
183
    dateTime($max = 'now', $timezone = date_default_timezone_get()) // DateTime('2008-04-25 08:37:17', 'UTC')
184
    dateTimeAD($max = 'now', $timezone = date_default_timezone_get()) // DateTime('1800-04-29 20:38:49', 'Europe/Paris')
185
    iso8601($max = 'now')                 // '1978-12-09T10:10:29+0000'
186
    date($format = 'Y-m-d', $max = 'now') // '1979-06-09'
187
    time($format = 'H:i:s', $max = 'now') // '20:49:42'
188
    dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = date_default_timezone_get()) // DateTime('2003-03-15 02:00:49', 'Africa/Lagos')
189
    dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days', $timezone = date_default_timezone_get()) // DateTime('2003-03-15 02:00:49', 'Antartica/Vostok')
190
    dateTimeThisCentury($max = 'now', $timezone = date_default_timezone_get())     // DateTime('1915-05-30 19:28:21', 'UTC')
191
    dateTimeThisDecade($max = 'now', $timezone = date_default_timezone_get())      // DateTime('2007-05-29 22:30:48', 'Europe/Paris')
192
    dateTimeThisYear($max = 'now', $timezone = date_default_timezone_get())        // DateTime('2011-02-27 20:52:14', 'Africa/Lagos')
193
    dateTimeThisMonth($max = 'now', $timezone = date_default_timezone_get())       // DateTime('2011-10-23 13:46:23', 'Antarctica/Vostok')
194
    amPm($max = 'now')                    // 'pm'
195
    dayOfMonth($max = 'now')              // '04'
196
    dayOfWeek($max = 'now')               // 'Friday'
197
    month($max = 'now')                   // '06'
198
    monthName($max = 'now')               // 'January'
199
    year($max = 'now')                    // '1993'
200
    century                               // 'VI'
201
    timezone                              // 'Europe/Paris'
202

    
203
### `Faker\Provider\Internet`
204

    
205
    email                   // 'tkshlerin@collins.com'
206
    safeEmail               // 'king.alford@example.org'
207
    freeEmail               // 'bradley72@gmail.com'
208
    companyEmail            // 'russel.durward@mcdermott.org'
209
    freeEmailDomain         // 'yahoo.com'
210
    safeEmailDomain         // 'example.org'
211
    userName                // 'wade55'
212
    password                // 'k&|X+a45*2['
213
    domainName              // 'wolffdeckow.net'
214
    domainWord              // 'feeney'
215
    tld                     // 'biz'
216
    url                     // 'http://www.skilesdonnelly.biz/aut-accusantium-ut-architecto-sit-et.html'
217
    slug                    // 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum'
218
    ipv4                    // '109.133.32.252'
219
    localIpv4               // '10.242.58.8'
220
    ipv6                    // '8e65:933d:22ee:a232:f1c1:2741:1f10:117c'
221
    macAddress              // '43:85:B7:08:10:CA'
222

    
223
### `Faker\Provider\UserAgent`
224

    
225
    userAgent              // 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350'
226
    chrome                 // 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312'
227
    firefox                // 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6'
228
    safari                 // 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_1 rv:3.0; en-US) AppleWebKit/534.11.3 (KHTML, like Gecko) Version/4.0 Safari/534.11.3'
229
    opera                  // 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00'
230
    internetExplorer       // 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)'
231

    
232
### `Faker\Provider\Payment`
233

    
234
    creditCardType          // 'MasterCard'
235
    creditCardNumber        // '4485480221084675'
236
    creditCardExpirationDate // 04/13
237
    creditCardExpirationDateString // '04/13'
238
    creditCardDetails       // array('MasterCard', '4485480221084675', 'Aleksander Nowak', '04/13')
239
    // Generates a random IBAN. Set $countryCode to null for a random country
240
    iban($countryCode)      // 'IT31A8497112740YZ575DJ28BP4'
241
    swiftBicNumber          // 'RZTIAT22263'
242

    
243
### `Faker\Provider\Color`
244

    
245
    hexcolor               // '#fa3cc2'
246
    rgbcolor               // '0,255,122'
247
    rgbColorAsArray        // array(0,255,122)
248
    rgbCssColor            // 'rgb(0,255,122)'
249
    safeColorName          // 'fuchsia'
250
    colorName              // 'Gainsbor'
251

    
252
### `Faker\Provider\File`
253

    
254
    fileExtension          // 'avi'
255
    mimeType               // 'video/x-msvideo'
256
    // Copy a random file from the source to the target directory and returns the fullpath or filename
257
    file($sourceDir = '/tmp', $targetDir = '/tmp') // '/path/to/targetDir/13b73edae8443990be1aa8f1a483bc27.jpg'
258
    file($sourceDir, $targetDir, false) // '13b73edae8443990be1aa8f1a483bc27.jpg'
259

    
260
### `Faker\Provider\Image`
261

    
262
    // Image generation provided by LoremPixel (http://lorempixel.com/)
263
    imageUrl($width = 640, $height = 480) // 'http://lorempixel.com/640/480/'
264
    imageUrl($width, $height, 'cats')     // 'http://lorempixel.com/800/600/cats/'
265
    imageUrl($width, $height, 'cats', true, 'Faker') // 'http://lorempixel.com/800/400/cats/Faker'
266
    imageUrl($width, $height, 'cats', true, 'Faker', true) // 'http://lorempixel.com/grey/800/400/cats/Faker/' Monochrome image
267
    image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg'
268
    image($dir, $width, $height, 'cats')  // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat!
269
    image($dir, $width, $height, 'cats', false) // '13b73edae8443990be1aa8f1a483bc27.jpg' it's a filename without path
270
    image($dir, $width, $height, 'cats', true, false) // it's a no randomize images (default: `true`)
271
    image($dir, $width, $height, 'cats', true, true, 'Faker') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat with 'Faker' text. Default, `null`.
272

    
273
### `Faker\Provider\Uuid`
274

    
275
    uuid                   // '7e57d004-2b97-0e7a-b45f-5387367791cd'
276

    
277
### `Faker\Provider\Barcode`
278

    
279
    ean13          // '4006381333931'
280
    ean8           // '73513537'
281
    isbn13         // '9790404436093'
282
    isbn10         // '4881416324'
283

    
284
### `Faker\Provider\Miscellaneous`
285

    
286
    boolean // false
287
    boolean($chanceOfGettingTrue = 50) // true
288
    md5           // 'de99a620c50f2990e87144735cd357e7'
289
    sha1          // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'
290
    sha256        // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'
291
    locale        // en_UK
292
    countryCode   // UK
293
    languageCode  // en
294
    currencyCode  // EUR
295
    emoji         // 😁
296

    
297
### `Faker\Provider\Biased`
298

    
299
    // get a random number between 10 and 20,
300
    // with more chances to be close to 20
301
    biasedNumberBetween($min = 10, $max = 20, $function = 'sqrt')
302

    
303
### `Faker\Provider\HtmlLorem`
304

    
305
    //Generate HTML document which is no more than 2 levels deep, and no more than 3 elements wide at any level.
306
    randomHtml(2,3)   // <html><head><title>Aut illo dolorem et accusantium eum.</title></head><body><form action="example.com" method="POST"><label for="username">sequi</label><input type="text" id="username"><label for="password">et</label><input type="password" id="password"></form><b>Id aut saepe non mollitia voluptas voluptas.</b><table><thead><tr><tr>Non consequatur.</tr><tr>Incidunt est.</tr><tr>Aut voluptatem.</tr><tr>Officia voluptas rerum quo.</tr><tr>Asperiores similique.</tr></tr></thead><tbody><tr><td>Sapiente dolorum dolorem sint laboriosam commodi qui.</td><td>Commodi nihil nesciunt eveniet quo repudiandae.</td><td>Voluptates explicabo numquam distinctio necessitatibus repellat.</td><td>Provident ut doloremque nam eum modi aspernatur.</td><td>Iusto inventore.</td></tr><tr><td>Animi nihil ratione id mollitia libero ipsa quia tempore.</td><td>Velit est officia et aut tenetur dolorem sed mollitia expedita.</td><td>Modi modi repudiandae pariatur voluptas rerum ea incidunt non molestiae eligendi eos deleniti.</td><td>Exercitationem voluptatibus dolor est iste quod molestiae.</td><td>Quia reiciendis.</td></tr><tr><td>Inventore impedit exercitationem voluptatibus rerum cupiditate.</td><td>Qui.</td><td>Aliquam.</td><td>Autem nihil aut et.</td><td>Dolor ut quia error.</td></tr><tr><td>Enim facilis iusto earum et minus rerum assumenda quis quia.</td><td>Reprehenderit ut sapiente occaecati voluptatum dolor voluptatem vitae qui velit.</td><td>Quod fugiat non.</td><td>Sunt nobis totam mollitia sed nesciunt est deleniti cumque.</td><td>Repudiandae quo.</td></tr><tr><td>Modi dicta libero quisquam doloremque qui autem.</td><td>Voluptatem aliquid saepe laudantium facere eos sunt dolor.</td><td>Est eos quis laboriosam officia expedita repellendus quia natus.</td><td>Et neque delectus quod fugit enim repudiandae qui.</td><td>Fugit soluta sit facilis facere repellat culpa magni voluptatem maiores tempora.</td></tr><tr><td>Enim dolores doloremque.</td><td>Assumenda voluptatem eum perferendis exercitationem.</td><td>Quasi in fugit deserunt ea perferendis sunt nemo consequatur dolorum soluta.</td><td>Maxime repellat qui numquam voluptatem est modi.</td><td>Alias rerum rerum hic hic eveniet.</td></tr><tr><td>Tempore voluptatem.</td><td>Eaque.</td><td>Et sit quas fugit iusto.</td><td>Nemo nihil rerum dignissimos et esse.</td><td>Repudiandae ipsum numquam.</td></tr><tr><td>Nemo sunt quia.</td><td>Sint tempore est neque ducimus harum sed.</td><td>Dicta placeat atque libero nihil.</td><td>Et qui aperiam temporibus facilis eum.</td><td>Ut dolores qui enim et maiores nesciunt.</td></tr><tr><td>Dolorum totam sint debitis saepe laborum.</td><td>Quidem corrupti ea.</td><td>Cum voluptas quod.</td><td>Possimus consequatur quasi dolorem ut et.</td><td>Et velit non hic labore repudiandae quis.</td></tr></tbody></table></body></html>
307

    
308
## Modifiers
309

    
310
Faker provides three special providers, `unique()`, `optional()`, and `valid()`, to be called before any provider.
311

    
312
```php
313
// unique() forces providers to return unique values
314
$values = array();
315
for ($i=0; $i < 10; $i++) {
316
  // get a random digit, but always a new one, to avoid duplicates
317
  $values []= $faker->unique()->randomDigit;
318
}
319
print_r($values); // [4, 1, 8, 5, 0, 2, 6, 9, 7, 3]
320

    
321
// providers with a limited range will throw an exception when no new unique value can be generated
322
$values = array();
323
try {
324
  for ($i=0; $i < 10; $i++) {
325
    $values []= $faker->unique()->randomDigitNotNull;
326
  }
327
} catch (\OverflowException $e) {
328
  echo "There are only 9 unique digits not null, Faker can't generate 10 of them!";
329
}
330

    
331
// you can reset the unique modifier for all providers by passing true as first argument
332
$faker->unique($reset = true)->randomDigitNotNull; // will not throw OverflowException since unique() was reset
333
// tip: unique() keeps one array of values per provider
334

    
335
// optional() sometimes bypasses the provider to return a default value instead (which defaults to NULL)
336
$values = array();
337
for ($i=0; $i < 10; $i++) {
338
  // get a random digit, but also null sometimes
339
  $values []= $faker->optional()->randomDigit;
340
}
341
print_r($values); // [1, 4, null, 9, 5, null, null, 4, 6, null]
342

    
343
// optional() accepts a weight argument to specify the probability of receiving the default value.
344
// 0 will always return the default value; 1 will always return the provider. Default weight is 0.5 (50% chance).
345
$faker->optional($weight = 0.1)->randomDigit; // 90% chance of NULL
346
$faker->optional($weight = 0.9)->randomDigit; // 10% chance of NULL
347

    
348
// optional() accepts a default argument to specify the default value to return.
349
// Defaults to NULL.
350
$faker->optional($weight = 0.5, $default = false)->randomDigit; // 50% chance of FALSE
351
$faker->optional($weight = 0.9, $default = 'abc')->word; // 10% chance of 'abc'
352

    
353
// valid() only accepts valid values according to the passed validator functions
354
$values = array();
355
$evenValidator = function($digit) {
356
	return $digit % 2 === 0;
357
};
358
for ($i=0; $i < 10; $i++) {
359
	$values []= $faker->valid($evenValidator)->randomDigit;
360
}
361
print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
362

    
363
// just like unique(), valid() throws an overflow exception when it can't generate a valid value
364
$values = array();
365
try {
366
  $faker->valid($evenValidator)->randomElement(1, 3, 5, 7, 9);
367
} catch (\OverflowException $e) {
368
  echo "Can't pick an even number in that set!";
369
}
370
```
371

    
372
## Localization
373

    
374
`Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale (en_US).
375

    
376
```php
377
<?php
378
$faker = Faker\Factory::create('fr_FR'); // create a French faker
379
for ($i=0; $i < 10; $i++) {
380
  echo $faker->name, "\n";
381
}
382
  // Luce du Coulon
383
  // Auguste Dupont
384
  // Roger Le Voisin
385
  // Alexandre Lacroix
386
  // Jacques Humbert-Roy
387
  // Thérèse Guillet-Andre
388
  // Gilles Gros-Bodin
389
  // Amélie Pires
390
  // Marcel Laporte
391
  // Geneviève Marchal
392
```
393

    
394
You can check available Faker locales in the source code, [under the `Provider` directory](https://github.com/fzaninotto/Faker/tree/master/src/Faker/Provider). The localization of Faker is an ongoing process, for which we need your help. Don't hesitate to create localized providers to your own locale and submit a PR!
395

    
396
## Populating Entities Using an ORM or an ODM
397

    
398
Faker provides adapters for Object-Relational and Object-Document Mappers (currently, [Propel](http://www.propelorm.org), [Doctrine2](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/), [CakePHP](http://cakephp.org), [Spot2](https://github.com/vlucas/spot2), [Mandango](https://github.com/mandango/mandango) and [Eloquent](https://laravel.com/docs/master/eloquent) are supported). These adapters ease the population of databases through the Entity classes provided by an ORM library (or the population of document stores using Document classes provided by an ODM library).
399

    
400
To populate entities, create a new populator class (using a generator instance as parameter), then list the class and number of all the entities that must be generated. To launch the actual data population, call the `execute()` method.
401

    
402
Here is an example showing how to populate 5 `Author` and 10 `Book` objects:
403

    
404
```php
405
<?php
406
$generator = \Faker\Factory::create();
407
$populator = new Faker\ORM\Propel\Populator($generator);
408
$populator->addEntity('Author', 5);
409
$populator->addEntity('Book', 10);
410
$insertedPKs = $populator->execute();
411
```
412

    
413
The populator uses name and column type guessers to populate each column with relevant data. For instance, Faker populates a column named `first_name` using the `firstName` formatter, and a column with a `TIMESTAMP` type using the `dateTime` formatter. The resulting entities are therefore coherent. If Faker misinterprets a column name, you can still specify a custom closure to be used for populating a particular column, using the third argument to `addEntity()`:
414

    
415
```php
416
<?php
417
$populator->addEntity('Book', 5, array(
418
  'ISBN' => function() use ($generator) { return $generator->ean13(); }
419
));
420
```
421

    
422
In this example, Faker will guess a formatter for all columns except `ISBN`, for which the given anonymous function will be used.
423

    
424
**Tip**: To ignore some columns, specify `null` for the column names in the third argument of `addEntity()`. This is usually necessary for columns added by a behavior:
425

    
426
```php
427
<?php
428
$populator->addEntity('Book', 5, array(
429
  'CreatedAt' => null,
430
  'UpdatedAt' => null,
431
));
432
```
433

    
434
Of course, Faker does not populate autoincremented primary keys. In addition, `Faker\ORM\Propel\Populator::execute()` returns the list of inserted PKs, indexed by class:
435

    
436
```php
437
<?php
438
print_r($insertedPKs);
439
// array(
440
//   'Author' => (34, 35, 36, 37, 38),
441
//   'Book'   => (456, 457, 458, 459, 470, 471, 472, 473, 474, 475)
442
// )
443
```
444

    
445
In the previous example, the `Book` and `Author` models share a relationship. Since `Author` entities are populated first, Faker is smart enough to relate the populated `Book` entities to one of the populated `Author` entities.
446

    
447
Lastly, if you want to execute an arbitrary function on an entity before insertion, use the fourth argument of the `addEntity()` method:
448

    
449
```php
450
<?php
451
$populator->addEntity('Book', 5, array(), array(
452
  function($book) { $book->publish(); },
453
));
454
```
455

    
456
## Seeding the Generator
457

    
458
You may want to get always the same generated data - for instance when using Faker for unit testing purposes. The generator offers a `seed()` method, which seeds the random number generator. Calling the same script twice with the same seed produces the same results.
459

    
460
```php
461
<?php
462
$faker = Faker\Factory::create();
463
$faker->seed(1234);
464

    
465
echo $faker->name; // 'Jess Mraz I';
466
```
467

    
468
> **Tip**: DateTime formatters won't reproduce the same fake data if you don't fix the `$max` value:
469
>
470
> ```php
471
> <?php
472
> // even when seeded, this line will return different results because $max varies
473
> $faker->dateTime(); // equivalent to $faker->dateTime($max = 'now')
474
> // make sure you fix the $max parameter
475
> $faker->dateTime('2014-02-25 08:37:17'); // will return always the same date when seeded
476
> ```
477
>
478
> **Tip**: Formatters won't reproduce the same fake data if you use the `rand()` php function. Use `$faker` or `mt_rand()` instead:
479
>
480
> ```php
481
> <?php
482
> // bad
483
> $faker->realText(rand(10,20));
484
> // good
485
> $faker->realText($faker->numberBetween(10,20));
486
> ```
487

    
488

    
489

    
490
## Faker Internals: Understanding Providers
491

    
492
A `Faker\Generator` alone can't do much generation. It needs `Faker\Provider` objects to delegate the data generation to them. `Faker\Factory::create()` actually creates a `Faker\Generator` bundled with the default providers. Here is what happens under the hood:
493

    
494
```php
495
<?php
496
$faker = new Faker\Generator();
497
$faker->addProvider(new Faker\Provider\en_US\Person($faker));
498
$faker->addProvider(new Faker\Provider\en_US\Address($faker));
499
$faker->addProvider(new Faker\Provider\en_US\PhoneNumber($faker));
500
$faker->addProvider(new Faker\Provider\en_US\Company($faker));
501
$faker->addProvider(new Faker\Provider\Lorem($faker));
502
$faker->addProvider(new Faker\Provider\Internet($faker));
503
````
504

    
505
Whenever you try to access a property on the `$faker` object, the generator looks for a method with the same name in all the providers attached to it. For instance, calling `$faker->name` triggers a call to `Faker\Provider\Person::name()`. And since Faker starts with the last provider, you can easily override existing formatters: just add a provider containing methods named after the formatters you want to override.
506

    
507
That means that you can easily add your own providers to a `Faker\Generator` instance. A provider is usually a class extending `\Faker\Provider\Base`. This parent class allows you to use methods like `lexify()` or `randomNumber()`; it also gives you access to formatters of other providers, through the protected `$generator` property. The new formatters are the public methods of the provider class.
508

    
509
Here is an example provider for populating Book data:
510

    
511
```php
512
<?php
513

    
514
namespace Faker\Provider;
515

    
516
class Book extends \Faker\Provider\Base
517
{
518
  public function title($nbWords = 5)
519
  {
520
    $sentence = $this->generator->sentence($nbWords);
521
    return substr($sentence, 0, strlen($sentence) - 1);
522
  }
523

    
524
  public function ISBN()
525
  {
526
    return $this->generator->ean13();
527
  }
528
}
529
```
530

    
531
To register this provider, just add a new instance of `\Faker\Provider\Book` to an existing generator:
532

    
533
```php
534
<?php
535
$faker->addProvider(new \Faker\Provider\Book($faker));
536
```
537

    
538
Now you can use the two new formatters like any other Faker formatter:
539

    
540
```php
541
<?php
542
$book = new Book();
543
$book->setTitle($faker->title);
544
$book->setISBN($faker->ISBN);
545
$book->setSummary($faker->text);
546
$book->setPrice($faker->randomNumber(2));
547
```
548

    
549
**Tip**: A provider can also be a Plain Old PHP Object. In that case, all the public methods of the provider become available to the generator.
550

    
551
## Real Life Usage
552

    
553
The following script generates a valid XML document:
554

    
555
```php
556
<?php
557
require_once '/path/to/Faker/src/autoload.php';
558
$faker = Faker\Factory::create();
559
?>
560
<?xml version="1.0" encoding="UTF-8"?>
561
<contacts>
562
<?php for ($i=0; $i < 10; $i++): ?>
563
  <contact firstName="<?php echo $faker->firstName ?>" lastName="<?php echo $faker->lastName ?>" email="<?php echo $faker->email ?>">
564
    <phone number="<?php echo $faker->phoneNumber ?>"/>
565
<?php if ($faker->boolean(25)): ?>
566
    <birth date="<?php echo $faker->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $faker->city ?>"/>
567
<?php endif; ?>
568
    <address>
569
      <street><?php echo $faker->streetAddress ?></street>
570
      <city><?php echo $faker->city ?></city>
571
      <postcode><?php echo $faker->postcode ?></postcode>
572
      <state><?php echo $faker->state ?></state>
573
    </address>
574
    <company name="<?php echo $faker->company ?>" catchPhrase="<?php echo $faker->catchPhrase ?>">
575
<?php if ($faker->boolean(33)): ?>
576
      <offer><?php echo $faker->bs ?></offer>
577
<?php endif; ?>
578
<?php if ($faker->boolean(33)): ?>
579
      <director name="<?php echo $faker->name ?>" />
580
<?php endif; ?>
581
    </company>
582
<?php if ($faker->boolean(15)): ?>
583
    <details>
584
<![CDATA[
585
<?php echo $faker->text(400) ?>
586
]]>
587
    </details>
588
<?php endif; ?>
589
  </contact>
590
<?php endfor; ?>
591
</contacts>
592
```
593

    
594
Running this script produces a document looking like:
595

    
596
```xml
597
<?xml version="1.0" encoding="UTF-8"?>
598
<contacts>
599
  <contact firstName="Ona" lastName="Bednar" email="schamberger.frank@wuckert.com">
600
    <phone number="1-265-479-1196x714"/>
601
    <address>
602
      <street>182 Harrison Cove</street>
603
      <city>North Lloyd</city>
604
      <postcode>45577</postcode>
605
      <state>Alabama</state>
606
    </address>
607
    <company name="Veum, Funk and Shanahan" catchPhrase="Function-based stable solution">
608
      <offer>orchestrate compelling web-readiness</offer>
609
    </company>
610
    <details>
611
<![CDATA[
612
Alias accusantium voluptatum autem nobis cumque neque modi. Voluptatem error molestiae consequatur alias.
613
Illum commodi molestiae aut repellat id. Et sit consequuntur aut et ullam asperiores. Cupiditate culpa voluptatem et mollitia dolor. Nisi praesentium qui ut.
614
]]>
615
    </details>
616
  </contact>
617
  <contact firstName="Aurelie" lastName="Paucek" email="alfonzo55@durgan.com">
618
    <phone number="863.712.1363x9425"/>
619
    <address>
620
      <street>90111 Hegmann Inlet</street>
621
      <city>South Geovanymouth</city>
622
      <postcode>69961-9311</postcode>
623
      <state>Colorado</state>
624
    </address>
625
    <company name="Krajcik-Grimes" catchPhrase="Switchable cohesive instructionset">
626
    </company>
627
  </contact>
628
  <contact firstName="Clifton" lastName="Kshlerin" email="kianna.wiegand@framiwyman.info">
629
    <phone number="692-194-4746"/>
630
    <address>
631
      <street>9791 Nona Corner</street>
632
      <city>Harberhaven</city>
633
      <postcode>74062-8191</postcode>
634
      <state>RhodeIsland</state>
635
    </address>
636
    <company name="Rosenbaum-Aufderhar" catchPhrase="Realigned asynchronous encryption">
637
    </company>
638
  </contact>
639
  <contact firstName="Alexandre" lastName="Orn" email="thelma37@erdmancorwin.biz">
640
    <phone number="189.655.8677x027"/>
641
    <address>
642
      <street>11161 Schultz Via</street>
643
      <city>Feilstad</city>
644
      <postcode>98019</postcode>
645
      <state>NewJersey</state>
646
    </address>
647
    <company name="O'Hara-Prosacco" catchPhrase="Re-engineered solution-oriented algorithm">
648
      <director name="Dr. Berenice Auer V" />
649
    </company>
650
    <details>
651
<![CDATA[
652
Ut itaque et quaerat doloremque eum praesentium. Rerum in saepe dolorem. Explicabo qui consequuntur commodi minima rem.
653
Harum temporibus rerum dolores. Non molestiae id dolorem placeat.
654
Aut asperiores nihil eius repellendus. Vero nihil corporis voluptatem explicabo commodi. Occaecati omnis blanditiis beatae quod aspernatur eos.
655
]]>
656
    </details>
657
  </contact>
658
  <contact firstName="Katelynn" lastName="Kohler" email="reinger.trudie@stiedemannjakubowski.com">
659
    <phone number="(665)713-1657"/>
660
    <address>
661
      <street>6106 Nader Village Suite 753</street>
662
      <city>McLaughlinstad</city>
663
      <postcode>43189-8621</postcode>
664
      <state>Missouri</state>
665
    </address>
666
    <company name="Herman-Tremblay" catchPhrase="Object-based explicit service-desk">
667
      <offer>expedite viral synergies</offer>
668
      <director name="Arden Deckow" />
669
    </company>
670
  </contact>
671
  <contact firstName="Blanca" lastName="Stark" email="tad27@feest.net">
672
    <phone number="168.719.4692x87177"/>
673
    <address>
674
      <street>7546 Kuvalis Plaza</street>
675
      <city>South Wilfrid</city>
676
      <postcode>77069</postcode>
677
      <state>Georgia</state>
678
    </address>
679
    <company name="Upton, Braun and Rowe" catchPhrase="Visionary leadingedge pricingstructure">
680
    </company>
681
  </contact>
682
  <contact firstName="Rene" lastName="Spencer" email="anibal28@armstrong.info">
683
    <phone number="715.222.0095x175"/>
684
    <birth date="2008-08-07" place="Zulaufborough"/>
685
    <address>
686
      <street>478 Daisha Landing Apt. 510</street>
687
      <city>West Lizethhaven</city>
688
      <postcode>30566-5362</postcode>
689
      <state>WestVirginia</state>
690
    </address>
691
    <company name="Wiza Inc" catchPhrase="Persevering reciprocal approach">
692
      <offer>orchestrate dynamic networks</offer>
693
      <director name="Erwin Nienow" />
694
    </company>
695
    <details>
696
<![CDATA[
697
Dolorem consequatur voluptates unde optio unde. Accusantium dolorem est est architecto impedit. Corrupti et provident quo.
698
Reprehenderit dolores aut quidem suscipit repudiandae corporis error. Molestiae enim aperiam illo.
699
Et similique qui non expedita quia dolorum. Ex rem incidunt ea accusantium temporibus minus non.
700
]]>
701
    </details>
702
  </contact>
703
  <contact firstName="Alessandro" lastName="Hagenes" email="tbreitenberg@oharagorczany.com">
704
    <phone number="1-284-958-6768"/>
705
    <address>
706
      <street>1251 Koelpin Mission</street>
707
      <city>North Revastad</city>
708
      <postcode>81620</postcode>
709
      <state>Maryland</state>
710
    </address>
711
    <company name="Stiedemann-Bruen" catchPhrase="Re-engineered 24/7 success">
712
    </company>
713
  </contact>
714
  <contact firstName="Novella" lastName="Rutherford" email="claud65@bogisich.biz">
715
    <phone number="(091)825-7971"/>
716
    <address>
717
      <street>6396 Langworth Hills Apt. 446</street>
718
      <city>New Carlos</city>
719
      <postcode>89399-0268</postcode>
720
      <state>Wyoming</state>
721
    </address>
722
    <company name="Stroman-Legros" catchPhrase="Expanded 4thgeneration moratorium">
723
      <director name="Earlene Bayer" />
724
    </company>
725
  </contact>
726
  <contact firstName="Andreane" lastName="Mann" email="meggie17@ornbaumbach.com">
727
    <phone number="941-659-9982x5689"/>
728
    <birth date="1934-02-21" place="Stantonborough"/>
729
    <address>
730
      <street>2246 Kreiger Station Apt. 291</street>
731
      <city>Kaydenmouth</city>
732
      <postcode>11397-1072</postcode>
733
      <state>Wyoming</state>
734
    </address>
735
    <company name="Lebsack, Bernhard and Kiehn" catchPhrase="Persevering actuating framework">
736
      <offer>grow sticky portals</offer>
737
    </company>
738
    <details>
739
<![CDATA[
740
Quia dolor ut quia error libero. Enim facilis iusto earum et minus rerum assumenda. Quia doloribus et reprehenderit ut. Occaecati voluptatum dolor voluptatem vitae qui velit quia.
741
Fugiat non in itaque sunt nobis totam. Sed nesciunt est deleniti cumque alias. Repudiandae quo aut numquam modi dicta libero.
742
]]>
743
    </details>
744
  </contact>
745
</contacts>
746
```
747

    
748
## Language specific formatters
749

    
750
### `Faker\Provider\ar_SA\Person`
751

    
752
```php
753
<?php
754

    
755
echo $faker->idNumber;      // ID number
756
echo $faker->nationalIdNumber // Citizen ID number
757
echo $faker->foreignerIdNumber // Foreigner ID number
758
echo $faker->companyIdNumber // Company ID number
759
```
760

    
761
### `Faker\Provider\ar_SA\Payment`
762

    
763
```php
764
<?php
765

    
766
echo $faker->bankAccountNumber // "SA0218IBYZVZJSEC8536V4XC"
767
```
768

    
769
### `Faker\Provider\at_AT\Payment`
770

    
771
```php
772
<?php
773

    
774
echo $faker->vat;           // "AT U12345678" - Austrian Value Added Tax number
775
echo $faker->vat(false);    // "ATU12345678" - unspaced Austrian Value Added Tax number
776
```
777

    
778
### `Faker\Provider\bg_BG\Payment`
779

    
780
```php
781
<?php
782

    
783
echo $faker->vat;           // "BG 0123456789" - Bulgarian Value Added Tax number
784
echo $faker->vat(false);    // "BG0123456789" - unspaced Bulgarian Value Added Tax number
785
```
786

    
787
### `Faker\Provider\cs_CZ\Address`
788

    
789
```php
790
<?php
791

    
792
echo $faker->region; // "Liberecký kraj"
793
```
794

    
795
### `Faker\Provider\cs_CZ\Company`
796

    
797
```php
798
<?php
799

    
800
// Generates a valid IČO
801
echo $faker->ico; // "69663963"
802
```
803

    
804
### `Faker\Provider\cs_CZ\DateTime`
805

    
806
```php
807
<?php
808

    
809
echo $faker->monthNameGenitive; // "prosince"
810
echo $faker->formattedDate; // "12. listopadu 2015"
811
```
812

    
813
### `Faker\Provider\cs_CZ\Person`
814

    
815
```php
816
<?php
817

    
818
echo $faker->birthNumber; // "7304243452"
819
```
820

    
821
### `Faker\Provider\da_DK\Person`
822

    
823
```php
824
<?php
825

    
826
// Generates a random CPR number
827
echo $faker->cpr; // "051280-2387"
828
```
829

    
830
### `Faker\Provider\da_DK\Address`
831

    
832
```php
833
<?php
834

    
835
// Generates a random 'kommune' name
836
echo $faker->kommune; // "Frederiksberg"
837

    
838
// Generates a random region name
839
echo $faker->region; // "Region Sjælland"
840
```
841

    
842
### `Faker\Provider\da_DK\Company`
843

    
844
```php
845
<?php
846

    
847
// Generates a random CVR number
848
echo $faker->cvr; // "32458723"
849

    
850
// Generates a random P number
851
echo $faker->p; // "5398237590"
852
```
853

    
854
### `Faker\Provider\de_DE\Payment`
855

    
856
```php
857
<?php
858

    
859
echo $faker->bankAccountNumber; // "DE41849025553661169313"
860
echo $faker->bank; // "Volksbank Stuttgart"
861

    
862
```
863

    
864
### `Faker\Provider\en_HK\Address`
865

    
866
```php
867
<?php
868

    
869
// Generates a fake town name based on the words commonly found in Hong Kong
870
echo $faker->town; // "Yuen Long"
871

    
872
// Generates a fake village name based on the words commonly found in Hong Kong
873
echo $faker->village; // "O Tau"
874

    
875
// Generates a fake estate name based on the words commonly found in Hong Kong
876
echo $faker->estate; // "Ching Lai Court"
877

    
878
```
879

    
880
### `Faker\Provider\en_HK\Phone`
881

    
882
```php
883
<?php
884

    
885
// Generates a Hong Kong mobile number (starting with 5, 6 or 9)
886
echo $faker->mobileNumber; // "92150087"
887

    
888
// Generates a Hong Kong landline number (starting with 2 or 3)
889
echo $faker->landlineNumber; // "32750132"
890

    
891
// Generates a Hong Kong fax number (starting with 7)
892
echo $faker->faxNumber; // "71937729"
893

    
894
```
895

    
896
### `Faker\Provider\en_NG\Address`
897

    
898
```php
899
<?php
900

    
901
// Generates a random region name
902
echo $faker->region; // 'Katsina'
903
```
904

    
905
### `Faker\Provider\en_NG\Person`
906

    
907
```php
908
<?php
909

    
910
// Generates a random person name
911
echo $faker->name; // 'Oluwunmi Mayowa'
912
```
913

    
914
### `Faker\Provider\en_NZ\Phone`
915

    
916
```php
917
<?php
918

    
919
// Generates a cell (mobile) phone number
920
echo $faker->cellNumber; // "021 123 4567"
921

    
922
// Generates a toll free number
923
echo $faker->tollFreeNumber; // "0800 123 456"
924

    
925
// Area Code
926
echo $faker->areaCode; // "03"
927
```
928

    
929
### `Faker\Provider\en_US\Payment`
930

    
931
```php
932
<?php
933

    
934
echo $faker->bankAccountNumber;  // '51915734310'
935
echo $faker->bankRoutingNumber;  // '212240302'
936
```
937

    
938
### `Faker\Provider\en_US\Person`
939

    
940
```php
941
<?php
942

    
943
// Generates a random Social Security Number
944
echo $faker->ssn; // '123-45-6789'
945
```
946

    
947
### `Faker\Provider\en_ZA\Company`
948

    
949
```php
950
<?php
951

    
952
// Generates a random company registration number
953
echo $faker->companyNumber; // 1999/789634/01
954
```
955

    
956
### `Faker\Provider\en_ZA\Person`
957

    
958
```php
959
<?php
960

    
961
// Generates a random national identification number
962
echo $faker->idNumber; // 6606192211041
963
```
964

    
965
### `Faker\Provider\en_ZA\PhoneNumber`
966

    
967
```php
968
<?php
969

    
970
// Generates a special rate toll free phone number
971
echo $faker->tollFreeNumber; // 0800 555 5555
972

    
973
// Generates a mobile phone number
974
echo $faker->mobileNumber; // 082 123 5555
975
```
976

    
977
### `Faker\Provider\es_ES\Person`
978

    
979
```php
980
<?php
981

    
982
// Generates a Documento Nacional de Identidad (DNI) number
983
echo $faker->dni; // '77446565E'
984
```
985

    
986
### `Faker\Provider\es_ES\Payment`
987

    
988
```php
989
<?php
990
// Generates a Código de identificación Fiscal (CIF) number
991
echo $faker->vat;           // "A35864370"
992
```
993

    
994
### `Faker\Provider\es_PE\Person`
995

    
996
```php
997
<?php
998

    
999
// Generates a Peruvian Documento Nacional de Identidad (DNI) number
1000
echo $faker->dni; // '83367512'
1001
```
1002

    
1003
### `Faker\Provider\fa_IR\Address`
1004

    
1005
```php
1006
<?php
1007

    
1008
// Generates a random building name
1009
echo $faker->building; // "ساختمان آفتاب"
1010

    
1011
// Returns a random city name
1012
echo $faker->city // "استان زنجان"
1013
```
1014

    
1015
### `Faker\Provider\fa_IR\Company`
1016

    
1017
```php
1018
<?php
1019

    
1020
// Generates a random contract type
1021
echo $faker->contract; // "رسمی"
1022
```
1023

    
1024
### `Faker\Provider\fi_FI\Payment`
1025

    
1026
```php
1027
<?php
1028

    
1029
// Generates a random bank account number
1030
echo $faker->bankAccountNumber; // "FI8350799879879616"
1031
```
1032

    
1033
### `Faker\Provider\fi_FI\Person`
1034

    
1035
```php
1036
<?php
1037

    
1038
//Generates a valid Finnish personal identity number (in Finnish - Henkilötunnus)
1039
echo $faker->personalIdentityNumber() // '170974-007J'
1040

    
1041
//Since the numbers are different for male and female persons, optionally you can specify gender.
1042
echo $faker->personalIdentityNumber(\DateTime::createFromFormat('Y-m-d', '2015-12-14'), 'female') // '141215A520B'
1043
```
1044

    
1045
### `Faker\Provider\fr_BE\Payment`
1046

    
1047
```php
1048
<?php
1049

    
1050
echo $faker->vat;           // "BE 0123456789" - Belgian Value Added Tax number
1051
echo $faker->vat(false);    // "BE0123456789" - unspaced Belgian Value Added Tax number
1052
```
1053

    
1054
### `Faker\Provider\fr_FR\Address`
1055

    
1056
```php
1057
<?php
1058

    
1059
// Generates a random department name
1060
echo $faker->departmentName; // "Haut-Rhin"
1061

    
1062
// Generates a random department number
1063
echo $faker->departmentNumber; // "2B"
1064

    
1065
// Generates a random department info (department number => department name)
1066
$faker->department; // array('18' => 'Cher');
1067

    
1068
// Generates a random region
1069
echo $faker->region; // "Saint-Pierre-et-Miquelon"
1070
```
1071

    
1072
### `Faker\Provider\fr_FR\Company`
1073

    
1074
```php
1075
<?php
1076

    
1077
// Generates a random SIREN number
1078
echo $faker->siren; // 082 250 104
1079

    
1080
// Generates a random SIRET number
1081
echo $faker->siret; // 347 355 708 00224
1082
```
1083

    
1084
### `Faker\Provider\fr_FR\Payment`
1085

    
1086
```php
1087
<?php
1088

    
1089
// Generates a random VAT
1090
echo $faker->vat; // FR 12 123 456 789
1091
```
1092

    
1093
### `Faker\Provider\fr_FR\Person`
1094

    
1095
```php
1096
<?php
1097

    
1098
// Generates a random NIR / Sécurité Sociale number
1099
echo $faker->nir; // 1 88 07 35 127 571 - 19
1100
```
1101

    
1102
### `Faker\Provider\he_IL\Payment`
1103

    
1104
```php
1105
<?php
1106

    
1107
echo $faker->bankAccountNumber // "IL392237392219429527697"
1108
```
1109

    
1110
### `Faker\Provider\hr_HR\Payment`
1111

    
1112
```php
1113
<?php
1114

    
1115
echo $faker->bankAccountNumber // "HR3789114847226078672"
1116
```
1117

    
1118
### `Faker\Provider\hu_HU\Payment`
1119

    
1120
```php
1121
<?php
1122

    
1123
// Generates a random bank account number
1124
echo $faker->bankAccountNumber; // "HU09904437680048220079300783"
1125
```
1126

    
1127
### `Faker\Provider\id_ID\Person`
1128

    
1129
```php
1130
<?php
1131

    
1132
// Generates a random Nomor Induk Kependudukan (NIK)
1133

    
1134
// first argument is gender, either Person::GENDER_MALE or Person::GENDER_FEMALE, if none specified random gender is used
1135
// second argument is birth date (DateTime object), if none specified, random birth date is used
1136
echo $faker->nik(); // "8522246001570940"
1137
```
1138

    
1139
### `Faker\Provider\it_IT\Company`
1140

    
1141
```php
1142
<?php
1143

    
1144
// Generates a random Vat Id
1145
echo $faker->vatId(); // "IT98746784967"
1146
```
1147

    
1148
### `Faker\Provider\it_IT\Person`
1149

    
1150
```php
1151
<?php
1152

    
1153
// Generates a random Tax Id code (Codice fiscale)
1154
echo $faker->taxId(); // "DIXDPZ44E08F367A"
1155
```
1156

    
1157
### `Faker\Provider\ja_JP\Person`
1158

    
1159
```php
1160
<?php
1161

    
1162
// Generates a 'kana' name
1163
echo $faker->kanaName($gender = null|'male'|'female') // "アオタ ミノル"
1164

    
1165
// Generates a 'kana' first name
1166
echo $faker->firstKanaName($gender = null|'male'|'female') // "ヒデキ"
1167

    
1168
// Generates a 'kana' first name on the male
1169
echo $faker->firstKanaNameMale // "ヒデキ"
1170

    
1171
// Generates a 'kana' first name on the female
1172
echo $faker->firstKanaNameFemale // "マアヤ"
1173

    
1174
// Generates a 'kana' last name
1175
echo $faker->lastKanaName; // "ナカジマ"
1176
```
1177

    
1178
### `Faker\Provider\ka_GE\Payment`
1179

    
1180
```php
1181
<?php
1182

    
1183
// Generates a random bank account number
1184
echo $faker->bankAccountNumber; // "GE33ZV9773853617253389"
1185
```
1186

    
1187
### `Faker\Provider\kk_KZ\Company`
1188

    
1189
```php
1190
<?php
1191

    
1192
// Generates an business identification number
1193
echo $faker->businessIdentificationNumber; // "150140000019"
1194
```
1195

    
1196
### `Faker\Provider\kk_KZ\Payment`
1197

    
1198
```php
1199
<?php
1200

    
1201
// Generates a random bank name
1202
echo $faker->bank; // "Қазкоммерцбанк"
1203

    
1204
// Generates a random bank account number
1205
echo $faker->bankAccountNumber; // "KZ1076321LO4H6X41I37"
1206
```
1207

    
1208
### `Faker\Provider\kk_KZ\Person`
1209

    
1210
```php
1211
<?php
1212

    
1213
// Generates an individual identification number
1214
echo $faker->individualIdentificationNumber; // "780322300455"
1215

    
1216
// Generates an individual identification number based on his/her birth date
1217
echo $faker->individualIdentificationNumber(new \DateTime('1999-03-01')); // "990301300455"
1218
```
1219

    
1220
### `Faker\Provider\ko_KR\Address`
1221

    
1222
```php
1223
<?php
1224

    
1225
// Generates a metropolitan city
1226
echo $faker->metropolitanCity; // "서울특별시"
1227

    
1228
// Generates a borough
1229
echo $faker->borough; // "강남구"
1230
```
1231

    
1232
### `Faker\Provider\lt_LT\Payment`
1233

    
1234
```php
1235
<?php
1236

    
1237
echo $faker->bankAccountNumber // "LT300848876740317118"
1238
```
1239

    
1240
### `Faker\Provider\lv_LV\Person`
1241

    
1242
```php
1243
<?php
1244

    
1245
// Generates a random personal identity card number
1246
echo $faker->personalIdentityNumber; // "140190-12301"
1247
```
1248

    
1249
### `Faker\Provider\ne_NP\Address`
1250

    
1251
```php
1252
<?php
1253

    
1254
//Generates a Nepali district name
1255
echo $faker->district;
1256

    
1257
//Generates a Nepali city name
1258
echo $faker->cityName;
1259
```
1260

    
1261
### `Faker\Provider\nl_BE\Payment`
1262

    
1263
```php
1264
<?php
1265

    
1266
echo $faker->vat;           // "BE 0123456789" - Belgian Value Added Tax number
1267
echo $faker->vat(false);    // "BE0123456789" - unspaced Belgian Value Added Tax number
1268
```
1269

    
1270
### `Faker\Provider\nl_NL\Company`
1271

    
1272
```php
1273
<?php
1274

    
1275
echo $faker->vat; // "NL123456789B01" - Dutch Value Added Tax number
1276
echo $faker->btw; // "NL123456789B01" - Dutch Value Added Tax number (alias)
1277
```
1278

    
1279
### `Faker\Provider\no_NO\Payment`
1280

    
1281
```php
1282
<?php
1283

    
1284
// Generates a random bank account number
1285
echo $faker->bankAccountNumber; // "NO3246764709816"
1286
```
1287

    
1288
### `Faker\Provider\pl_PL\Person`
1289

    
1290
```php
1291
<?php
1292

    
1293
// Generates a random PESEL number
1294
echo $faker->pesel; // "40061451555"
1295
// Generates a random personal identity card number
1296
echo $faker->personalIdentityNumber; // "AKX383360"
1297
// Generates a random taxpayer identification number (NIP)
1298
echo $faker->taxpayerIdentificationNumber; // '8211575109'
1299
```
1300

    
1301
### `Faker\Provider\pl_PL\Company`
1302

    
1303
```php
1304
<?php
1305

    
1306
// Generates a random REGON number
1307
echo $faker->regon; // "714676680"
1308
// Generates a random local REGON number
1309
echo $faker->regonLocal; // "15346111382836"
1310
```
1311

    
1312
### `Faker\Provider\pl_PL\Payment`
1313

    
1314
```php
1315
<?php
1316

    
1317
// Generates a random bank name
1318
echo $faker->bank; // "Narodowy Bank Polski"
1319
// Generates a random bank account number
1320
echo $faker->bankAccountNumber; // "PL14968907563953822118075816"
1321
```
1322

    
1323
### `Faker\Provider\pt_PT\Person`
1324

    
1325
```php
1326
<?php
1327

    
1328
// Generates a random taxpayer identification number (in portuguese - Número de Identificação Fiscal NIF)
1329
echo $faker->taxpayerIdentificationNumber; // '165249277'
1330
```
1331

    
1332
### `Faker\Provider\pt_BR\Address`
1333

    
1334
```php
1335
<?php
1336

    
1337
// Generates a random region name
1338
echo $faker->region; // 'Nordeste'
1339

    
1340
// Generates a random region abbreviation
1341
echo $faker->regionAbbr; // 'NE'
1342
```
1343

    
1344
### `Faker\Provider\pt_BR\PhoneNumber`
1345

    
1346
```php
1347
<?php
1348

    
1349
echo $faker->areaCode;  // 21
1350
echo $faker->cellphone; // 9432-5656
1351
echo $faker->landline;  // 2654-3445
1352
echo $faker->phone;     // random landline, 8-digit or 9-digit cellphone number
1353

    
1354
// Using the phone functions with a false argument returns unformatted numbers
1355
echo $faker->cellphone(false); // 74336667
1356

    
1357
// cellphone() has a special second argument to add the 9th digit. Ignored if generated a Radio number
1358
echo $faker->cellphone(true, true); // 98983-3945 or 7343-1290
1359

    
1360
// Using the "Number" suffix adds area code to the phone
1361
echo $faker->cellphoneNumber;       // (11) 98309-2935
1362
echo $faker->landlineNumber(false); // 3522835934
1363
echo $faker->phoneNumber;           // formatted, random landline or cellphone (obeying the 9th digit rule)
1364
echo $faker->phoneNumberCleared;    // not formatted, random landline or cellphone (obeying the 9th digit rule)
1365
```
1366

    
1367
### `Faker\Provider\pt_BR\Person`
1368

    
1369
```php
1370
<?php
1371

    
1372
// The name generator may include double first or double last names, plus title and suffix
1373
echo $faker->name; // 'Sr. Luis Adriano Sepúlveda Filho'
1374

    
1375
// Valid document generators have a boolean argument to remove formatting
1376
echo $faker->cpf;        // '145.343.345-76'
1377
echo $faker->cpf(false); // '45623467866'
1378
echo $faker->rg;         // '84.405.736-3'
1379
```
1380

    
1381
### `Faker\Provider\pt_BR\Company`
1382

    
1383
```php
1384
<?php
1385

    
1386
// Generates a Brazilian formatted and valid CNPJ
1387
echo $faker->cnpj;        // '23.663.478/0001-24'
1388
echo $faker->cnpj(false); // '23663478000124'
1389
```
1390

    
1391
### `Faker\Provider\ro_MD\Payment`
1392

    
1393
```php
1394
<?php
1395

    
1396
// Generates a random bank account number
1397
echo $faker->bankAccountNumber; // "MD83BQW1CKMUW34HBESDP3A8"
1398
```
1399

    
1400
### `Faker\Provider\ro_RO\Payment`
1401

    
1402
```php
1403
<?php
1404

    
1405
// Generates a random bank account number
1406
echo $faker->bankAccountNumber; // "RO55WRJE3OE8X3YQI7J26U1E"
1407
```
1408

    
1409
### `Faker\Provider\ro_RO\Person`
1410

    
1411
```php
1412
<?php
1413

    
1414
// Generates a random male name prefix/title
1415
echo $faker->prefixMale; // "ing."
1416
// Generates a random female name prefix/title
1417
echo $faker->prefixFemale; // "d-na."
1418
// Generates a random male first name
1419
echo $faker->firstNameMale; // "Adrian"
1420
// Generates a random female first name
1421
echo $faker->firstNameFemale; // "Miruna"
1422

    
1423

    
1424
// Generates a random Personal Numerical Code (CNP)
1425
echo $faker->cnp; // "2800523081231"
1426
// Valid option values:
1427
//    $gender: null (random), male, female
1428
//    $dateOfBirth (1800+): null (random), Y-m-d, Y-m (random day), Y (random month and day)
1429
//          i.e. '1981-06-16', '2015-03', '1900'
1430
//    $county: 2 letter ISO 3166-2:RO county codes and B1, B2, B3, B4, B5, B6 for Bucharest's 6 sectors
1431
//    $isResident true/false flag if the person resides in Romania
1432
echo $faker->cnp($gender = null, $dateOfBirth = null, $county = null, $isResident = true);
1433

    
1434
```
1435

    
1436
### `Faker\Provider\ro_RO\PhoneNumber`
1437

    
1438
```php
1439
<?php
1440

    
1441
// Generates a random toll-free phone number
1442
echo $faker->tollFreePhoneNumber; // "0800123456"
1443
// Generates a random premium-rate phone number
1444
echo $faker->premiumRatePhoneNumber; // "0900123456"
1445
```
1446

    
1447
### `Faker\Provider\ru_RU\Payment`
1448

    
1449
```php
1450
<?php
1451

    
1452
// Generates a Russian bank name (based on list of real russian banks)
1453
echo $faker->bank; // "ОТП Банк"
1454

    
1455
//Generate a Russian Tax Payment Number for Company
1456
echo $faker->inn; //  7813540735
1457

    
1458
//Generate a Russian Tax Code for Company
1459
echo $faker->kpp; // 781301001
1460
```
1461

    
1462
### `Faker\Provider\sv_SE\Payment`
1463

    
1464
```php
1465
<?php
1466

    
1467
// Generates a random bank account number
1468
echo $faker->bankAccountNumber; // "SE5018548608468284909192"
1469
```
1470

    
1471
### `Faker\Provider\sv_SE\Person`
1472

    
1473
```php
1474
<?php
1475

    
1476
//Generates a valid Swedish personal identity number (in Swedish - Personnummer)
1477
echo $faker->personalIdentityNumber() // '950910-0799'
1478

    
1479
//Since the numbers are different for male and female persons, optionally you can specify gender.
1480
echo $faker->personalIdentityNumber('female') // '950910-0781'
1481
```
1482

    
1483

    
1484
### `Faker\Provider\zh_CN\Payment`
1485

    
1486
```php
1487
<?php
1488

    
1489
// Generates a random bank name (based on list of real chinese banks)
1490
echo $faker->bank; // '中国建设银行'
1491
```
1492

    
1493
### `Faker\Provider\uk_UA\Payment`
1494

    
1495
```php
1496
<?php
1497

    
1498
// Generates an Ukraine bank name (based on list of real Ukraine banks)
1499
echo $faker->bank; // "Ощадбанк"
1500
```
1501

    
1502
### `Faker\Provider\zh_TW\Person`
1503

    
1504
```php
1505
<?php
1506

    
1507
// Generates a random personal identify number
1508
echo $faker->personalIdentityNumber; // A223456789
1509
```
1510

    
1511
### `Faker\Provider\zh_TW\Company`
1512

    
1513
```php
1514
<?php
1515

    
1516
// Generates a random VAT / Company Tax number
1517
echo $faker->VAT; //23456789
1518
```
1519

    
1520

    
1521
## Third-Party Libraries Extending/Based On Faker
1522

    
1523
* Symfony2 bundles:
1524
  * [BazingaFakerBundle](https://github.com/willdurand/BazingaFakerBundle): Put the awesome Faker library into the Symfony2 DIC and populate your database with fake data.
1525
  * [AliceBundle](https://github.com/hautelook/AliceBundle), [AliceFixturesBundle](https://github.com/h4cc/AliceFixturesBundle): Bundles for using [Alice](https://packagist.org/packages/nelmio/alice) and Faker with data fixtures. Able to use Doctrine ORM as well as Doctrine MongoDB ODM.
1526
* [FakerServiceProvider](https://github.com/EmanueleMinotto/FakerServiceProvider): Faker Service Provider for Silex
1527
* [faker-cli](https://github.com/bit3/faker-cli): Command Line Tool for the Faker PHP library
1528
* [Factory Muffin](https://github.com/thephpleague/factory-muffin): enable the rapid creation of objects (PHP port of factory-girl)
1529
* [CompanyNameGenerator](https://github.com/fzaninotto/CompanyNameGenerator): Generate names for English tech companies with class
1530
* [PlaceholdItProvider](https://github.com/EmanueleMinotto/PlaceholdItProvider): Generate images using placehold.it
1531
* [datalea](https://github.com/spyrit/datalea) A highly customizable random test data generator web app
1532
* [newage-ipsum](https://github.com/frequenc1/newage-ipsum): A new aged ipsum provider for the faker library inspired by http://sebpearce.com/bullshit/
1533
* [xml-faker](https://github.com/prewk/xml-faker): Create fake XML with Faker
1534
* [faker-context](https://github.com/denheck/faker-context): Behat context using Faker to generate testdata
1535
* [CronExpressionGenerator](https://github.com/swekaj/CronExpressionGenerator): Faker provider for generating random, valid cron expressions.
1536
* [pragmafabrik/Pomm2Faker](https://github.com/pragmafabrik/Pomm2Faker): Faker client for Pomm database framework (PostgreSQL)
1537
* [nelmio/alice](https://packagist.org/packages/nelmio/alice): Fixtures/object generator with a yaml DSL that can use Faker as data generator.
1538
* [CakePHP 2.x Fake Seeder Plugin](https://github.com/ravage84/cakephp-fake-seeder) A CakePHP 2.x shell to seed your database with fake and/or fixed data.
1539
* [images-generator](https://github.com/bruceheller/images-generator): An image generator provider using GD for placeholder type pictures
1540
* [pattern-lab/plugin-php-faker](https://github.com/pattern-lab/plugin-php-faker): Pattern Lab is a Styleguide, Component Library, and Prototyping tool. This creates unique content each time Pattern Lab is generated.
1541
* [guidocella/eloquent-populator](https://github.com/guidocella/eloquent-populator): Adapter for Laravel's Eloquent ORM.
1542
* [tamperdata/exiges](https://github.com/tamperdata/exiges): Faker provider for generating random temperatures
1543

    
1544
## License
1545

    
1546
Faker is released under the MIT Licence. See the bundled LICENSE file for details.
(9-9/9)