Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

readme.md 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. # Faker
  2. 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.
  3. 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).
  4. Faker requires PHP >= 5.3.3.
  5. [![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)
  6. # Table of Contents
  7. - [Installation](#installation)
  8. - [Basic Usage](#basic-usage)
  9. - [Formatters](#formatters)
  10. - [Base](#fakerproviderbase)
  11. - [Lorem Ipsum Text](#fakerproviderlorem)
  12. - [Person](#fakerprovideren_usperson)
  13. - [Address](#fakerprovideren_usaddress)
  14. - [Phone Number](#fakerprovideren_usphonenumber)
  15. - [Company](#fakerprovideren_uscompany)
  16. - [Real Text](#fakerprovideren_ustext)
  17. - [Date and Time](#fakerproviderdatetime)
  18. - [Internet](#fakerproviderinternet)
  19. - [User Agent](#fakerprovideruseragent)
  20. - [Payment](#fakerproviderpayment)
  21. - [Color](#fakerprovidercolor)
  22. - [File](#fakerproviderfile)
  23. - [Image](#fakerproviderimage)
  24. - [Uuid](#fakerprovideruuid)
  25. - [Barcode](#fakerproviderbarcode)
  26. - [Miscellaneous](#fakerprovidermiscellaneous)
  27. - [Biased](#fakerproviderbiased)
  28. - [Modifiers](#modifiers)
  29. - [Localization](#localization)
  30. - [Populating Entities Using an ORM or an ODM](#populating-entities-using-an-orm-or-an-odm)
  31. - [Seeding the Generator](#seeding-the-generator)
  32. - [Faker Internals: Understanding Providers](#faker-internals-understanding-providers)
  33. - [Real Life Usage](#real-life-usage)
  34. - [Language specific formatters](#language-specific-formatters)
  35. - [Third-Party Libraries Extending/Based On Faker](#third-party-libraries-extendingbased-on-faker)
  36. - [License](#license)
  37. ## Installation
  38. ```sh
  39. composer require fzaninotto/faker
  40. ```
  41. ## Basic Usage
  42. 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.
  43. ```php
  44. <?php
  45. // require the Faker autoloader
  46. require_once '/path/to/Faker/src/autoload.php';
  47. // alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader for instance)
  48. // use the factory to create a Faker\Generator instance
  49. $faker = Faker\Factory::create();
  50. // generate data by accessing properties
  51. echo $faker->name;
  52. // 'Lucy Cechtelar';
  53. echo $faker->address;
  54. // "426 Jordy Lodge
  55. // Cartwrightshire, SC 88120-6700"
  56. echo $faker->text;
  57. // Dolores sit sint laboriosam dolorem culpa et autem. Beatae nam sunt fugit
  58. // et sit et mollitia sed.
  59. // Fuga deserunt tempora facere magni omnis. Omnis quia temporibus laudantium
  60. // sit minima sint.
  61. ```
  62. 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)`.
  63. ```php
  64. <?php
  65. for ($i=0; $i < 10; $i++) {
  66. echo $faker->name, "\n";
  67. }
  68. // Adaline Reichel
  69. // Dr. Santa Prosacco DVM
  70. // Noemy Vandervort V
  71. // Lexi O'Conner
  72. // Gracie Weber
  73. // Roscoe Johns
  74. // Emmett Lebsack
  75. // Keegan Thiel
  76. // Wellington Koelpin II
  77. // Ms. Karley Kiehn V
  78. ```
  79. **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).
  80. ## Formatters
  81. 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.
  82. ### `Faker\Provider\Base`
  83. randomDigit // 7
  84. randomDigitNotNull // 5
  85. randomNumber($nbDigits = NULL) // 79907610
  86. randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932
  87. numberBetween($min = 1000, $max = 9000) // 8567
  88. randomLetter // 'b'
  89. // returns randomly ordered subsequence of a provided array
  90. randomElements($array = array ('a','b','c'), $count = 1) // array('c')
  91. randomElement($array = array ('a','b','c')) // 'b'
  92. shuffle('hello, world') // 'rlo,h eoldlw'
  93. shuffle(array(1, 2, 3)) // array(2, 1, 3)
  94. numerify('Hello ###') // 'Hello 609'
  95. lexify('Hello ???') // 'Hello wgt'
  96. bothify('Hello ##??') // 'Hello 42jz'
  97. asciify('Hello ***') // 'Hello R6+'
  98. regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej
  99. ### `Faker\Provider\Lorem`
  100. word // 'aut'
  101. words($nb = 3, $asText = false) // array('porro', 'sed', 'magni')
  102. sentence($nbWords = 6, $variableNbWords = true) // 'Sit vitae voluptas sint non voluptates.'
  103. sentences($nb = 3, $asText = false) // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.')
  104. 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.'
  105. 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.')
  106. text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.'
  107. ### `Faker\Provider\en_US\Person`
  108. title($gender = null|'male'|'female') // 'Ms.'
  109. titleMale // 'Mr.'
  110. titleFemale // 'Ms.'
  111. suffix // 'Jr.'
  112. name($gender = null|'male'|'female') // 'Dr. Zane Stroman'
  113. firstName($gender = null|'male'|'female') // 'Maynard'
  114. firstNameMale // 'Maynard'
  115. firstNameFemale // 'Rachel'
  116. lastName // 'Zulauf'
  117. ### `Faker\Provider\en_US\Address`
  118. cityPrefix // 'Lake'
  119. secondaryAddress // 'Suite 961'
  120. state // 'NewMexico'
  121. stateAbbr // 'OH'
  122. citySuffix // 'borough'
  123. streetSuffix // 'Keys'
  124. buildingNumber // '484'
  125. city // 'West Judge'
  126. streetName // 'Keegan Trail'
  127. streetAddress // '439 Karley Loaf Suite 897'
  128. postcode // '17916'
  129. address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
  130. country // 'Falkland Islands (Malvinas)'
  131. latitude($min = -90, $max = 90) // 77.147489
  132. longitude($min = -180, $max = 180) // 86.211205
  133. ### `Faker\Provider\en_US\PhoneNumber`
  134. phoneNumber // '201-886-0269 x3767'
  135. tollFreePhoneNumber // '(888) 937-7238'
  136. e164PhoneNumber // '+27113456789'
  137. ### `Faker\Provider\en_US\Company`
  138. catchPhrase // 'Monitored regional contingency'
  139. bs // 'e-enable robust architectures'
  140. company // 'Bogan-Treutel'
  141. companySuffix // 'and Sons'
  142. jobTitle // 'Cashier'
  143. ### `Faker\Provider\en_US\Text`
  144. 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."
  145. ### `Faker\Provider\DateTime`
  146. unixTime($max = 'now') // 58781813
  147. dateTime($max = 'now', $timezone = date_default_timezone_get()) // DateTime('2008-04-25 08:37:17', 'UTC')
  148. dateTimeAD($max = 'now', $timezone = date_default_timezone_get()) // DateTime('1800-04-29 20:38:49', 'Europe/Paris')
  149. iso8601($max = 'now') // '1978-12-09T10:10:29+0000'
  150. date($format = 'Y-m-d', $max = 'now') // '1979-06-09'
  151. time($format = 'H:i:s', $max = 'now') // '20:49:42'
  152. dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = date_default_timezone_get()) // DateTime('2003-03-15 02:00:49', 'Africa/Lagos')
  153. dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days', $timezone = date_default_timezone_get()) // DateTime('2003-03-15 02:00:49', 'Antartica/Vostok')
  154. dateTimeThisCentury($max = 'now') // DateTime('1915-05-30 19:28:21')
  155. dateTimeThisDecade($max = 'now') // DateTime('2007-05-29 22:30:48')
  156. dateTimeThisYear($max = 'now') // DateTime('2011-02-27 20:52:14')
  157. dateTimeThisMonth($max = 'now') // DateTime('2011-10-23 13:46:23')
  158. amPm($max = 'now') // 'pm'
  159. dayOfMonth($max = 'now') // '04'
  160. dayOfWeek($max = 'now') // 'Friday'
  161. month($max = 'now') // '06'
  162. monthName($max = 'now') // 'January'
  163. year($max = 'now') // '1993'
  164. century // 'VI'
  165. timezone // 'Europe/Paris'
  166. ### `Faker\Provider\Internet`
  167. email // 'tkshlerin@collins.com'
  168. safeEmail // 'king.alford@example.org'
  169. freeEmail // 'bradley72@gmail.com'
  170. companyEmail // 'russel.durward@mcdermott.org'
  171. freeEmailDomain // 'yahoo.com'
  172. safeEmailDomain // 'example.org'
  173. userName // 'wade55'
  174. password // 'k&|X+a45*2['
  175. domainName // 'wolffdeckow.net'
  176. domainWord // 'feeney'
  177. tld // 'biz'
  178. url // 'http://www.skilesdonnelly.biz/aut-accusantium-ut-architecto-sit-et.html'
  179. slug // 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum'
  180. ipv4 // '109.133.32.252'
  181. localIpv4 // '10.242.58.8'
  182. ipv6 // '8e65:933d:22ee:a232:f1c1:2741:1f10:117c'
  183. macAddress // '43:85:B7:08:10:CA'
  184. ### `Faker\Provider\UserAgent`
  185. userAgent // 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350'
  186. chrome // 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312'
  187. firefox // 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6'
  188. 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'
  189. opera // 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00'
  190. internetExplorer // 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)'
  191. ### `Faker\Provider\Payment`
  192. creditCardType // 'MasterCard'
  193. creditCardNumber // '4485480221084675'
  194. creditCardExpirationDate // 04/13
  195. creditCardExpirationDateString // '04/13'
  196. creditCardDetails // array('MasterCard', '4485480221084675', 'Aleksander Nowak', '04/13')
  197. // Generates a random IBAN. Set $countryCode to null for a random country
  198. iban($countryCode) // 'IT31A8497112740YZ575DJ28BP4'
  199. swiftBicNumber // 'RZTIAT22263'
  200. ### `Faker\Provider\Color`
  201. hexcolor // '#fa3cc2'
  202. rgbcolor // '0,255,122'
  203. rgbColorAsArray // array(0,255,122)
  204. rgbCssColor // 'rgb(0,255,122)'
  205. safeColorName // 'fuchsia'
  206. colorName // 'Gainsbor'
  207. ### `Faker\Provider\File`
  208. fileExtension // 'avi'
  209. mimeType // 'video/x-msvideo'
  210. // Copy a random file from the source to the target directory and returns the fullpath or filename
  211. file($sourceDir = '/tmp', $targetDir = '/tmp') // '/path/to/targetDir/13b73edae8443990be1aa8f1a483bc27.jpg'
  212. file($sourceDir, $targetDir, false) // '13b73edae8443990be1aa8f1a483bc27.jpg'
  213. ### `Faker\Provider\Image`
  214. // Image generation provided by LoremPixel (http://lorempixel.com/)
  215. imageUrl($width = 640, $height = 480) // 'http://lorempixel.com/640/480/'
  216. imageUrl($width, $height, 'cats') // 'http://lorempixel.com/800/600/cats/'
  217. imageUrl($width, $height, 'cats', true, 'Faker') // 'http://lorempixel.com/800/400/cats/Faker'
  218. image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg'
  219. image($dir, $width, $height, 'cats') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat!
  220. image($dir, $width, $height, 'cats', true, 'Faker') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat with Faker text
  221. ### `Faker\Provider\Uuid`
  222. uuid // '7e57d004-2b97-0e7a-b45f-5387367791cd'
  223. ### `Faker\Provider\Barcode`
  224. ean13 // '4006381333931'
  225. ean8 // '73513537'
  226. isbn13 // '9790404436093'
  227. isbn10 // '4881416324'
  228. ### `Faker\Provider\Miscellaneous`
  229. boolean // false
  230. boolean($chanceOfGettingTrue = 50) // true
  231. md5 // 'de99a620c50f2990e87144735cd357e7'
  232. sha1 // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'
  233. sha256 // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'
  234. locale // en_UK
  235. countryCode // UK
  236. languageCode // en
  237. currencyCode // EUR
  238. ### `Faker\Provider\Biased`
  239. // get a random number between 10 and 20,
  240. // with more chances to be close to 20
  241. biasedNumberBetween($min = 10, $max = 20, $function = 'sqrt')
  242. ## Modifiers
  243. Faker provides three special providers, `unique()`, `optional()`, and `valid()`, to be called before any provider.
  244. ```php
  245. // unique() forces providers to return unique values
  246. $values = array();
  247. for ($i=0; $i < 10; $i++) {
  248. // get a random digit, but always a new one, to avoid duplicates
  249. $values []= $faker->unique()->randomDigit;
  250. }
  251. print_r($values); // [4, 1, 8, 5, 0, 2, 6, 9, 7, 3]
  252. // providers with a limited range will throw an exception when no new unique value can be generated
  253. $values = array();
  254. try {
  255. for ($i=0; $i < 10; $i++) {
  256. $values []= $faker->unique()->randomDigitNotNull;
  257. }
  258. } catch (\OverflowException $e) {
  259. echo "There are only 9 unique digits not null, Faker can't generate 10 of them!";
  260. }
  261. // you can reset the unique modifier for all providers by passing true as first argument
  262. $faker->unique($reset = true)->randomDigitNotNull; // will not throw OverflowException since unique() was reset
  263. // tip: unique() keeps one array of values per provider
  264. // optional() sometimes bypasses the provider to return a default value instead (which defaults to NULL)
  265. $values = array();
  266. for ($i=0; $i < 10; $i++) {
  267. // get a random digit, but also null sometimes
  268. $values []= $faker->optional()->randomDigit;
  269. }
  270. print_r($values); // [1, 4, null, 9, 5, null, null, 4, 6, null]
  271. // optional() accepts a weight argument to specify the probability of receiving the default value.
  272. // 0 will always return the default value; 1 will always return the provider. Default weight is 0.5 (50% chance).
  273. $faker->optional($weight = 0.1)->randomDigit; // 90% chance of NULL
  274. $faker->optional($weight = 0.9)->randomDigit; // 10% chance of NULL
  275. // optional() accepts a default argument to specify the default value to return.
  276. // Defaults to NULL.
  277. $faker->optional($weight = 0.5, $default = false)->randomDigit; // 50% chance of FALSE
  278. $faker->optional($weight = 0.9, $default = 'abc')->word; // 10% chance of 'abc'
  279. // valid() only accepts valid values according to the passed validator functions
  280. $values = array();
  281. $evenValidator = function($digit) {
  282. return $digit % 2 === 0;
  283. };
  284. for ($i=0; $i < 10; $i++) {
  285. $values []= $faker->valid($evenValidator)->randomDigit;
  286. }
  287. print_r($values); // [0, 4, 8, 4, 2, 6, 0, 8, 8, 6]
  288. // just like unique(), valid() throws an overflow exception when it can't generate a valid value
  289. $values = array();
  290. try {
  291. $faker->valid($evenValidator)->randomElement(1, 3, 5, 7, 9);
  292. } catch (\OverflowException $e) {
  293. echo "Can't pick an even number in that set!";
  294. }
  295. ```
  296. ## Localization
  297. `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_EN).
  298. ```php
  299. <?php
  300. $faker = Faker\Factory::create('fr_FR'); // create a French faker
  301. for ($i=0; $i < 10; $i++) {
  302. echo $faker->name, "\n";
  303. }
  304. // Luce du Coulon
  305. // Auguste Dupont
  306. // Roger Le Voisin
  307. // Alexandre Lacroix
  308. // Jacques Humbert-Roy
  309. // Thérèse Guillet-Andre
  310. // Gilles Gros-Bodin
  311. // Amélie Pires
  312. // Marcel Laporte
  313. // Geneviève Marchal
  314. ```
  315. 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!
  316. ## Populating Entities Using an ORM or an ODM
  317. 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) and [Mandango](https://github.com/mandango/mandango) 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).
  318. 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.
  319. Here is an example showing how to populate 5 `Author` and 10 `Book` objects:
  320. ```php
  321. <?php
  322. $generator = \Faker\Factory::create();
  323. $populator = new Faker\ORM\Propel\Populator($generator);
  324. $populator->addEntity('Author', 5);
  325. $populator->addEntity('Book', 10);
  326. $insertedPKs = $populator->execute();
  327. ```
  328. 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()`:
  329. ```php
  330. <?php
  331. $populator->addEntity('Book', 5, array(
  332. 'ISBN' => function() use ($generator) { return $generator->ean13(); }
  333. ));
  334. ```
  335. In this example, Faker will guess a formatter for all columns except `ISBN`, for which the given anonymous function will be used.
  336. **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:
  337. ```php
  338. <?php
  339. $populator->addEntity('Book', 5, array(
  340. 'CreatedAt' => null,
  341. 'UpdatedAt' => null,
  342. ));
  343. ```
  344. 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:
  345. ```php
  346. <?php
  347. print_r($insertedPKs);
  348. // array(
  349. // 'Author' => (34, 35, 36, 37, 38),
  350. // 'Book' => (456, 457, 458, 459, 470, 471, 472, 473, 474, 475)
  351. // )
  352. ```
  353. 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.
  354. Lastly, if you want to execute an arbitrary function on an entity before insertion, use the fourth argument of the `addEntity()` method:
  355. ```php
  356. <?php
  357. $populator->addEntity('Book', 5, array(), array(
  358. function($book) { $book->publish(); },
  359. ));
  360. ```
  361. ## Seeding the Generator
  362. 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.
  363. ```php
  364. <?php
  365. $faker = Faker\Factory::create();
  366. $faker->seed(1234);
  367. echo $faker->name; // 'Jess Mraz I';
  368. ```
  369. > **Tip**: DateTime formatters won't reproduce the same fake data if you don't fix the `$max` value:
  370. >
  371. > ```php
  372. > <?php
  373. > // even when seeded, this line will return different results because $max varies
  374. > $faker->dateTime(); // equivalent to $faker->dateTime($max = 'now')
  375. > // make sure you fix the $max parameter
  376. > $faker->dateTime('2014-02-25 08:37:17'); // will return always the same date when seeded
  377. > ```
  378. >
  379. > **Tip**: Formatters won't reproduce the same fake data if you use the `rand()` php function. Use `$faker` or `mt_rand()` instead:
  380. >
  381. > ```php
  382. > <?php
  383. > // bad
  384. > $faker->realText(rand(10,20));
  385. > // good
  386. > $faker->realText($faker->numberBetween(10,20));
  387. > ```
  388. ## Faker Internals: Understanding Providers
  389. 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:
  390. ```php
  391. <?php
  392. $faker = new Faker\Generator();
  393. $faker->addProvider(new Faker\Provider\en_US\Person($faker));
  394. $faker->addProvider(new Faker\Provider\en_US\Address($faker));
  395. $faker->addProvider(new Faker\Provider\en_US\PhoneNumber($faker));
  396. $faker->addProvider(new Faker\Provider\en_US\Company($faker));
  397. $faker->addProvider(new Faker\Provider\Lorem($faker));
  398. $faker->addProvider(new Faker\Provider\Internet($faker));
  399. ````
  400. 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.
  401. 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.
  402. Here is an example provider for populating Book data:
  403. ```php
  404. <?php
  405. namespace Faker\Provider;
  406. class Book extends \Faker\Provider\Base
  407. {
  408. public function title($nbWords = 5)
  409. {
  410. $sentence = $this->generator->sentence($nbWords);
  411. return substr($sentence, 0, strlen($sentence) - 1);
  412. }
  413. public function ISBN()
  414. {
  415. return $this->generator->ean13();
  416. }
  417. }
  418. ```
  419. To register this provider, just add a new instance of `\Faker\Provider\Book` to an existing generator:
  420. ```php
  421. <?php
  422. $faker->addProvider(new \Faker\Provider\Book($faker));
  423. ```
  424. Now you can use the two new formatters like any other Faker formatter:
  425. ```php
  426. <?php
  427. $book = new Book();
  428. $book->setTitle($faker->title);
  429. $book->setISBN($faker->ISBN);
  430. $book->setSummary($faker->text);
  431. $book->setPrice($faker->randomNumber(2));
  432. ```
  433. **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.
  434. ## Real Life Usage
  435. The following script generates a valid XML document:
  436. ```php
  437. <?php
  438. require_once '/path/to/Faker/src/autoload.php';
  439. $faker = Faker\Factory::create();
  440. ?>
  441. <?xml version="1.0" encoding="UTF-8"?>
  442. <contacts>
  443. <?php for ($i=0; $i < 10; $i++): ?>
  444. <contact firstName="<?php echo $faker->firstName ?>" lastName="<?php echo $faker->lastName ?>" email="<?php echo $faker->email ?>"/>
  445. <phone number="<?php echo $faker->phoneNumber ?>"/>
  446. <?php if ($faker->boolean(25)): ?>
  447. <birth date="<?php echo $faker->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $faker->city ?>"/>
  448. <?php endif; ?>
  449. <address>
  450. <street><?php echo $faker->streetAddress ?></street>
  451. <city><?php echo $faker->city ?></city>
  452. <postcode><?php echo $faker->postcode ?></postcode>
  453. <state><?php echo $faker->state ?></state>
  454. </address>
  455. <company name="<?php echo $faker->company ?>" catchPhrase="<?php echo $faker->catchPhrase ?>">
  456. <?php if ($faker->boolean(33)): ?>
  457. <offer><?php echo $faker->bs ?></offer>
  458. <?php endif; ?>
  459. <?php if ($faker->boolean(33)): ?>
  460. <director name="<?php echo $faker->name ?>" />
  461. <?php endif; ?>
  462. </company>
  463. <?php if ($faker->boolean(15)): ?>
  464. <details>
  465. <![CDATA[
  466. <?php echo $faker->text(400) ?>
  467. ]]>
  468. </details>
  469. <?php endif; ?>
  470. </contact>
  471. <?php endfor; ?>
  472. </contacts>
  473. ```
  474. Running this script produces a document looking like:
  475. ```xml
  476. <?xml version="1.0" encoding="UTF-8"?>
  477. <contacts>
  478. <contact firstName="Ona" lastName="Bednar" email="schamberger.frank@wuckert.com"/>
  479. <phone number="1-265-479-1196x714"/>
  480. <address>
  481. <street>182 Harrison Cove</street>
  482. <city>North Lloyd</city>
  483. <postcode>45577</postcode>
  484. <state>Alabama</state>
  485. </address>
  486. <company name="Veum, Funk and Shanahan" catchPhrase="Function-based stable solution">
  487. <offer>orchestrate compelling web-readiness</offer>
  488. </company>
  489. <details>
  490. <![CDATA[
  491. Alias accusantium voluptatum autem nobis cumque neque modi. Voluptatem error molestiae consequatur alias.
  492. Illum commodi molestiae aut repellat id. Et sit consequuntur aut et ullam asperiores. Cupiditate culpa voluptatem et mollitia dolor. Nisi praesentium qui ut.
  493. ]]>
  494. </details>
  495. </contact>
  496. <contact firstName="Aurelie" lastName="Paucek" email="alfonzo55@durgan.com"/>
  497. <phone number="863.712.1363x9425"/>
  498. <address>
  499. <street>90111 Hegmann Inlet</street>
  500. <city>South Geovanymouth</city>
  501. <postcode>69961-9311</postcode>
  502. <state>Colorado</state>
  503. </address>
  504. <company name="Krajcik-Grimes" catchPhrase="Switchable cohesive instructionset">
  505. </company>
  506. </contact>
  507. <contact firstName="Clifton" lastName="Kshlerin" email="kianna.wiegand@framiwyman.info"/>
  508. <phone number="692-194-4746"/>
  509. <address>
  510. <street>9791 Nona Corner</street>
  511. <city>Harberhaven</city>
  512. <postcode>74062-8191</postcode>
  513. <state>RhodeIsland</state>
  514. </address>
  515. <company name="Rosenbaum-Aufderhar" catchPhrase="Realigned asynchronous encryption">
  516. </company>
  517. </contact>
  518. <contact firstName="Alexandre" lastName="Orn" email="thelma37@erdmancorwin.biz"/>
  519. <phone number="189.655.8677x027"/>
  520. <address>
  521. <street>11161 Schultz Via</street>
  522. <city>Feilstad</city>
  523. <postcode>98019</postcode>
  524. <state>NewJersey</state>
  525. </address>
  526. <company name="O'Hara-Prosacco" catchPhrase="Re-engineered solution-oriented algorithm">
  527. <director name="Dr. Berenice Auer V" />
  528. </company>
  529. <details>
  530. <![CDATA[
  531. Ut itaque et quaerat doloremque eum praesentium. Rerum in saepe dolorem. Explicabo qui consequuntur commodi minima rem.
  532. Harum temporibus rerum dolores. Non molestiae id dolorem placeat.
  533. Aut asperiores nihil eius repellendus. Vero nihil corporis voluptatem explicabo commodi. Occaecati omnis blanditiis beatae quod aspernatur eos.
  534. ]]>
  535. </details>
  536. </contact>
  537. <contact firstName="Katelynn" lastName="Kohler" email="reinger.trudie@stiedemannjakubowski.com"/>
  538. <phone number="(665)713-1657"/>
  539. <address>
  540. <street>6106 Nader Village Suite 753</street>
  541. <city>McLaughlinstad</city>
  542. <postcode>43189-8621</postcode>
  543. <state>Missouri</state>
  544. </address>
  545. <company name="Herman-Tremblay" catchPhrase="Object-based explicit service-desk">
  546. <offer>expedite viral synergies</offer>
  547. <director name="Arden Deckow" />
  548. </company>
  549. </contact>
  550. <contact firstName="Blanca" lastName="Stark" email="tad27@feest.net"/>
  551. <phone number="168.719.4692x87177"/>
  552. <address>
  553. <street>7546 Kuvalis Plaza</street>
  554. <city>South Wilfrid</city>
  555. <postcode>77069</postcode>
  556. <state>Georgia</state>
  557. </address>
  558. <company name="Upton, Braun and Rowe" catchPhrase="Visionary leadingedge pricingstructure">
  559. </company>
  560. </contact>
  561. <contact firstName="Rene" lastName="Spencer" email="anibal28@armstrong.info"/>
  562. <phone number="715.222.0095x175"/>
  563. <birth date="2008-08-07" place="Zulaufborough"/>
  564. <address>
  565. <street>478 Daisha Landing Apt. 510</street>
  566. <city>West Lizethhaven</city>
  567. <postcode>30566-5362</postcode>
  568. <state>WestVirginia</state>
  569. </address>
  570. <company name="Wiza Inc" catchPhrase="Persevering reciprocal approach">
  571. <offer>orchestrate dynamic networks</offer>
  572. <director name="Erwin Nienow" />
  573. </company>
  574. <details>
  575. <![CDATA[
  576. Dolorem consequatur voluptates unde optio unde. Accusantium dolorem est est architecto impedit. Corrupti et provident quo.
  577. Reprehenderit dolores aut quidem suscipit repudiandae corporis error. Molestiae enim aperiam illo.
  578. Et similique qui non expedita quia dolorum. Ex rem incidunt ea accusantium temporibus minus non.
  579. ]]>
  580. </details>
  581. </contact>
  582. <contact firstName="Alessandro" lastName="Hagenes" email="tbreitenberg@oharagorczany.com"/>
  583. <phone number="1-284-958-6768"/>
  584. <address>
  585. <street>1251 Koelpin Mission</street>
  586. <city>North Revastad</city>
  587. <postcode>81620</postcode>
  588. <state>Maryland</state>
  589. </address>
  590. <company name="Stiedemann-Bruen" catchPhrase="Re-engineered 24/7 success">
  591. </company>
  592. </contact>
  593. <contact firstName="Novella" lastName="Rutherford" email="claud65@bogisich.biz"/>
  594. <phone number="(091)825-7971"/>
  595. <address>
  596. <street>6396 Langworth Hills Apt. 446</street>
  597. <city>New Carlos</city>
  598. <postcode>89399-0268</postcode>
  599. <state>Wyoming</state>
  600. </address>
  601. <company name="Stroman-Legros" catchPhrase="Expanded 4thgeneration moratorium">
  602. <director name="Earlene Bayer" />
  603. </company>
  604. </contact>
  605. <contact firstName="Andreane" lastName="Mann" email="meggie17@ornbaumbach.com"/>
  606. <phone number="941-659-9982x5689"/>
  607. <birth date="1934-02-21" place="Stantonborough"/>
  608. <address>
  609. <street>2246 Kreiger Station Apt. 291</street>
  610. <city>Kaydenmouth</city>
  611. <postcode>11397-1072</postcode>
  612. <state>Wyoming</state>
  613. </address>
  614. <company name="Lebsack, Bernhard and Kiehn" catchPhrase="Persevering actuating framework">
  615. <offer>grow sticky portals</offer>
  616. </company>
  617. <details>
  618. <![CDATA[
  619. 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.
  620. Fugiat non in itaque sunt nobis totam. Sed nesciunt est deleniti cumque alias. Repudiandae quo aut numquam modi dicta libero.
  621. ]]>
  622. </details>
  623. </contact>
  624. </contacts>
  625. ```
  626. ## Language specific formatters
  627. ### `Faker\Provider\ar_SA\Person`
  628. ```php
  629. <?php
  630. echo $faker->idNumber; // ID number
  631. echo $faker->nationalIdNumber // Citizen ID number
  632. echo $faker->foreignerIdNumber // Foreigner ID number
  633. ```
  634. ### `Faker\Provider\at_AT\Payment`
  635. ```php
  636. <?php
  637. echo $faker->vat; // "AT U12345678" - Austrian Value Added Tax number
  638. echo $faker->vat(false); // "ATU12345678" - unspaced Austrian Value Added Tax number
  639. ```
  640. ### `Faker\Provider\bg_BG\Payment`
  641. ```php
  642. <?php
  643. echo $faker->vat; // "BG 0123456789" - Bulgarian Value Added Tax number
  644. echo $faker->vat(false); // "BG0123456789" - unspaced Bulgarian Value Added Tax number
  645. ```
  646. ### `Faker\Provider\cs_CZ\Address`
  647. ```php
  648. <?php
  649. echo $faker->region; // "Liberecký kraj"
  650. ```
  651. ### `Faker\Provider\cs_CZ\Company`
  652. ```php
  653. <?php
  654. // Generates a valid IČO
  655. echo $faker->ico; // "69663963"
  656. ```
  657. ### `Faker\Provider\cs_CZ\DateTime`
  658. ```php
  659. <?php
  660. echo $faker->monthNameGenitive; // "prosince"
  661. echo $faker->formattedDate; // "12. listopadu 2015"
  662. ```
  663. ### `Faker\Provider\cs_CZ\Person`
  664. ```php
  665. <?php
  666. echo $faker->birthNumber; // "7304243452"
  667. ```
  668. ### `Faker\Provider\da_DK\Person`
  669. ```php
  670. <?php
  671. // Generates a random CPR number
  672. echo $faker->cpr; // "051280-2387"
  673. ```
  674. ### `Faker\Provider\da_DK\Address`
  675. ```php
  676. <?php
  677. // Generates a random 'kommune' name
  678. echo $faker->kommune; // "Frederiksberg"
  679. // Generates a random region name
  680. echo $faker->region; // "Region Sjælland"
  681. ```
  682. ### `Faker\Provider\da_DK\Company`
  683. ```php
  684. <?php
  685. // Generates a random CVR number
  686. echo $faker->cvr; // "32458723"
  687. // Generates a random P number
  688. echo $faker->p; // "5398237590"
  689. ```
  690. ### `Faker\Provider\en_NZ\Phone`
  691. ```php
  692. <?php
  693. // Generates a cell (mobile) phone number
  694. echo $faker->cellNumber; // "021 123 4567"
  695. // Generates a toll free number
  696. echo $faker->tollFreeNumber; // "0800 123 456"
  697. // Area Code
  698. echo $faker->areaCode; // "03"
  699. ```
  700. ### `Faker\Provider\en_US\Payment`
  701. ```php
  702. <?php
  703. echo $faker->bankAccountNumber; // '51915734310'
  704. echo $faker->bankRoutingNumber; // '212240302'
  705. ```
  706. ### `Faker\Provider\en_ZA\Company`
  707. ```php
  708. <?php
  709. // Generates a random company registration number
  710. echo $faker->companyNumber; // 1999/789634/01
  711. ```
  712. ### `Faker\Provider\en_ZA\PhoneNumber`
  713. ```php
  714. <?php
  715. // Generates a special rate toll free phone number
  716. echo $faker->tollFreeNumber; // 0800 555 5555
  717. // Generates a mobile phone number
  718. echo $faker->mobileNumber; // 082 123 5555
  719. ```
  720. ### `Faker\Provider\es_ES\Person`
  721. ```php
  722. <?php
  723. // Generates a Documento Nacional de Identidad (DNI) number
  724. echo $faker->dni; // '77446565E'
  725. ```
  726. ### `Faker\Provider\fr_BE\Payment`
  727. ```php
  728. <?php
  729. echo $faker->vat; // "BE 0123456789" - Belgian Value Added Tax number
  730. echo $faker->vat(false); // "BE0123456789" - unspaced Belgian Value Added Tax number
  731. ```
  732. ### `Faker\Provider\fr_FR\Address`
  733. ```php
  734. <?php
  735. // Generates a random department name
  736. echo $faker->departmentName; // "Haut-Rhin"
  737. // Generates a random department number
  738. echo $faker->departmentNumber; // "2B"
  739. // Generates a random department info (department number => department name)
  740. $faker->department; // array('18' => 'Cher');
  741. // Generates a random region
  742. echo $faker->region; // "Saint-Pierre-et-Miquelon"
  743. ```
  744. ### `Faker\Provider\fr_FR\Company`
  745. ```php
  746. <?php
  747. // Generates a random SIREN number
  748. echo $faker->siren; // 082 250 104
  749. // Generates a random SIRET number
  750. echo $faker->siret; // 347 355 708 00224
  751. ```
  752. ### `Faker\Provider\hu_HU\Payment`
  753. ```php
  754. <?php
  755. // Generates a random bank account number
  756. echo $faker->bankAccountNumber; // "HU09904437680048220079300783"
  757. ```
  758. ### `Faker\Provider\it_IT\Company`
  759. ```php
  760. <?php
  761. // Generates a random Vat Id
  762. echo $faker->vatId(); // "IT98746784967"
  763. ```
  764. ### `Faker\Provider\it_IT\Person`
  765. ```php
  766. <?php
  767. // Generates a random Tax Id code (Codice fiscale)
  768. echo $faker->taxId(); // "DIXDPZ44E08F367A"
  769. ```
  770. ### `Faker\Provider\ja_JP\Person`
  771. ```php
  772. <?php
  773. // Generates a 'kana' name
  774. echo $faker->kanaName; // "アオタ ミノル"
  775. // Generates a 'kana' first name
  776. echo $faker->firstKanaName; // "ハルカ"
  777. // Generates a 'kana' last name
  778. echo $faker->lastKanaName; // "ナカジマ"
  779. ```
  780. ### `Faker\Provider\ka_GE\Payment`
  781. ```php
  782. <?php
  783. // Generates a random bank account number
  784. echo $faker->bankAccountNumber; // "GE33ZV9773853617253389"
  785. ```
  786. ### `Faker\Provider\kk_KZ\Company`
  787. ```php
  788. <?php
  789. // Generates an business identification number
  790. echo $faker->businessIdentificationNumber; // "150140000019"
  791. ```
  792. ### `Faker\Provider\kk_KZ\Payment`
  793. ```php
  794. <?php
  795. // Generates a random bank name
  796. echo $faker->bank; // "Қазкоммерцбанк"
  797. // Generates a random bank account number
  798. echo $faker->bankAccountNumber; // "KZ1076321LO4H6X41I37"
  799. ```
  800. ### `Faker\Provider\kk_KZ\Person`
  801. ```php
  802. <?php
  803. // Generates an individual identification number
  804. echo $faker->individualIdentificationNumber; // "780322300455"
  805. ```
  806. ### `Faker\Provider\ko_KR\Address`
  807. ```php
  808. <?php
  809. // Generates a metropolitan city
  810. echo $faker->metropolitanCity; // "서울특별시"
  811. // Generates a borough
  812. echo $faker->borough; // "강남구"
  813. ```
  814. ### `Faker\Provider\lv_LV\Person`
  815. ```php
  816. <?php
  817. // Generates a random personal identity card number
  818. echo $faker->personalIdentityNumber; // "140190-12301"
  819. ```
  820. ### `Faker\Provider\ne_NP\Address`
  821. ```php
  822. <?php
  823. //Generates a Nepali district name
  824. echo $faker->district;
  825. //Generates a Nepali city name
  826. echo $faker->cityName;
  827. ```
  828. ### `Faker\Provider\nl_BE\Payment`
  829. ```php
  830. <?php
  831. echo $faker->vat; // "BE 0123456789" - Belgian Value Added Tax number
  832. echo $faker->vat(false); // "BE0123456789" - unspaced Belgian Value Added Tax number
  833. ```
  834. ### `Faker\Provider\nl_NL\Company`
  835. ```php
  836. <?php
  837. echo $faker->vat; // "NL123456789B01" - Dutch Value Added Tax number
  838. echo $faker->btw; // "NL123456789B01" - Dutch Value Added Tax number (alias)
  839. ```
  840. ### `Faker\Provider\no_NO\Payment`
  841. ```php
  842. <?php
  843. // Generates a random bank account number
  844. echo $faker->bankAccountNumber; // "NO3246764709816"
  845. ```
  846. ### `Faker\Provider\pl_PL\Person`
  847. ```php
  848. <?php
  849. // Generates a random PESEL number
  850. echo $faker->pesel; // "40061451555"
  851. // Generates a random personal identity card number
  852. echo $faker->personalIdentityNumber; // "AKX383360"
  853. // Generates a random taxpayer identification number (NIP)
  854. echo $faker->taxpayerIdentificationNumber; // '8211575109'
  855. ```
  856. ### `Faker\Provider\pl_PL\Company`
  857. ```php
  858. <?php
  859. // Generates a random REGON number
  860. echo $faker->regon; // "714676680"
  861. // Generates a random local REGON number
  862. echo $faker->regonLocal; // "15346111382836"
  863. ```
  864. ### `Faker\Provider\pl_PL\Payment`
  865. ```php
  866. <?php
  867. // Generates a random bank name
  868. echo $faker->bank; // "Narodowy Bank Polski"
  869. // Generates a random bank account number
  870. echo $faker->bankAccountNumber; // "PL14968907563953822118075816"
  871. ```
  872. ### `Faker\Provider\pt_PT\Person`
  873. ```php
  874. <?php
  875. // Generates a random taxpayer identification number (in portuguese - Número de Identificação Fiscal NIF)
  876. echo $faker->taxpayerIdentificationNumber; // '165249277'
  877. ```
  878. ### `Faker\Provider\pt_BR\Address`
  879. ```php
  880. <?php
  881. // Generates a random region name
  882. echo $faker->region; // 'Nordeste'
  883. // Generates a random region abbreviation
  884. echo $faker->regionAbbr; // 'NE'
  885. ```
  886. ### `Faker\Provider\pt_BR\PhoneNumber`
  887. ```php
  888. <?php
  889. echo $faker->areaCode; // 21
  890. echo $faker->cellphone; // 9432-5656
  891. echo $faker->landline; // 2654-3445
  892. echo $faker->phone; // random landline, 8-digit or 9-digit cellphone number
  893. // Using the phone functions with a false argument returns unformatted numbers
  894. echo $faker->cellphone(false); // 74336667
  895. // cellphone() has a special second argument to add the 9th digit. Ignored if generated a Radio number
  896. echo $faker->cellphone(true, true); // 98983-3945 or 7343-1290
  897. // Using the "Number" suffix adds area code to the phone
  898. echo $faker->cellphoneNumber; // (11) 98309-2935
  899. echo $faker->landlineNumber(false); // 3522835934
  900. echo $faker->phoneNumber; // formatted, random landline or cellphone (obbeying the 9th digit rule)
  901. echo $faker->phoneNumberCleared; // not formatted, random landline or cellphone (obbeying the 9th digit rule)
  902. ```
  903. ### `Faker\Provider\pt_BR\Person`
  904. ```php
  905. <?php
  906. // The name generator may include double first or double last names, plus title and suffix
  907. echo $faker->name; // 'Sr. Luis Adriano Sepúlveda Filho'
  908. // Valid document generators have a boolean argument to remove formatting
  909. echo $faker->cpf; // '145.343.345-76'
  910. echo $faker->cpf(false); // '45623467866'
  911. echo $faker->rg; // '84.405.736-3'
  912. ```
  913. ### `Faker\Provider\pt_BR\Company`
  914. ```php
  915. <?php
  916. // Generates a Brazilian formated and valid CNPJ
  917. echo $faker->cnpj; // '23.663.478/0001-24'
  918. echo $faker->cnpj(false); // '23663478000124'
  919. ```
  920. ### `Faker\Provider\ro_MD\Payment`
  921. ```php
  922. <?php
  923. // Generates a random bank account number
  924. echo $faker->bankAccountNumber; // "MD83BQW1CKMUW34HBESDP3A8"
  925. ```
  926. ### `Faker\Provider\ro_RO\Payment`
  927. ```php
  928. <?php
  929. // Generates a random bank account number
  930. echo $faker->bankAccountNumber; // "RO55WRJE3OE8X3YQI7J26U1E"
  931. ```
  932. ### `Faker\Provider\ro_RO\Person`
  933. ```php
  934. <?php
  935. // Generates a random male name prefix/title
  936. echo $faker->prefixMale; // "ing."
  937. // Generates a random female name prefix/title
  938. echo $faker->prefixFemale; // "d-na."
  939. // Generates a random male fist name
  940. echo $faker->firstNameMale; // "Adrian"
  941. // Generates a random female fist name
  942. echo $faker->firstNameFemale; // "Miruna"
  943. // Generates a random Personal Numerical Code (CNP)
  944. echo $faker->cnp; // "2800523081231"
  945. echo $faker->cnp($gender = NULL, $century = NULL, $county = NULL);
  946. // Valid option values:
  947. // $gender: m, f, 1, 2
  948. // $century: 1800, 1900, 2000, 1, 2, 3, 4, 5, 6
  949. // $county: 2 letter ISO 3166-2:RO county codes and B1-B6 for Bucharest's 6 sectors
  950. ```
  951. ### `Faker\Provider\ro_RO\PhoneNumber`
  952. ```php
  953. <?php
  954. // Generates a random toll-free phone number
  955. echo $faker->tollFreePhoneNumber; // "0800123456"
  956. // Generates a random premium-rate phone number
  957. echo $faker->premiumRatePhoneNumber; // "0900123456"
  958. ```
  959. ### `Faker\Provider\ru_RU\Payment`
  960. ```php
  961. <?php
  962. // Generates a Russian bank name (based on list of real russian banks)
  963. echo $faker->bank; // "ОТП Банк"
  964. ```
  965. ### `Faker\Provider\sv_SE\Payment`
  966. ```php
  967. <?php
  968. // Generates a random bank account number
  969. echo $faker->bankAccountNumber; // "SE5018548608468284909192"
  970. ```
  971. ### `Faker\Provider\sv_SE\Person`
  972. ```php
  973. <?php
  974. //Generates a valid Swedish personal identity number (in Swedish - Personnummer)
  975. echo $faker->personalIdentityNumber() // '950910-0799'
  976. //Since the numbers are different for male and female persons, optionally you can specify gender.
  977. echo $faker->personalIdentityNumber('female') // '950910-0781'
  978. ```
  979. ### `Faker\Provider\zh_CN\Payment`
  980. ```php
  981. <?php
  982. // Generates a random bank name (based on list of real chinese banks)
  983. echo $faker->bank; // '中国建设银行'
  984. ```
  985. ## Third-Party Libraries Extending/Based On Faker
  986. * Symfony2 bundles:
  987. * [BazingaFakerBundle](https://github.com/willdurand/BazingaFakerBundle): Put the awesome Faker library into the Symfony2 DIC and populate your database with fake data.
  988. * [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.
  989. * [FakerServiceProvider](https://github.com/EmanueleMinotto/FakerServiceProvider): Faker Service Provider for Silex
  990. * [faker-cli](https://github.com/bit3/faker-cli): Command Line Tool for the Faker PHP library
  991. * [Factory Muffin](https://github.com/thephpleague/factory-muffin): enable the rapid creation of objects (PHP port of factory-girl)
  992. * [CompanyNameGenerator](https://github.com/fzaninotto/CompanyNameGenerator): Generate names for English tech companies with class
  993. * [PlaceholdItProvider](https://github.com/EmanueleMinotto/PlaceholdItProvider): Generate images using placehold.it
  994. * [datalea](https://github.com/spyrit/datalea) A highly customizable random test data generator web app
  995. * [newage-ipsum](https://github.com/frequenc1/newage-ipsum): A new aged ipsum provider for the faker library inspired by http://sebpearce.com/bullshit/
  996. * [xml-faker](https://github.com/prewk/xml-faker): Create fake XML with Faker
  997. * [faker-context](https://github.com/denheck/faker-context): Behat context using Faker to generate testdata
  998. * [CronExpressionGenerator](https://github.com/swekaj/CronExpressionGenerator): Faker provider for generating random, valid cron expressions.
  999. * [pragmafabrik/Pomm2Faker](https://github.com/pragmafabrik/Pomm2Faker): Faker client for Pomm database framework (PostgreSQL)
  1000. * [nelmio/alice](https://packagist.org/packages/nelmio/alice): Fixtures/object generator with a yaml DSL that can use Faker as data generator.
  1001. * [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.
  1002. * [images-generator](https://github.com/bruceheller/images-generator): An image generator provider using GD for placeholder type pictures
  1003. ## License
  1004. Faker is released under the MIT Licence. See the bundled LICENSE file for details.