選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

readme.md 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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](http://faker.rubyforge.org/).
  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://secure.travis-ci.org/fzaninotto/Faker.png)](http://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. ## Basic Usage
  7. 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.
  8. ```php
  9. <?php
  10. // require the Faker autoloader
  11. require_once '/path/to/Faker/src/autoload.php';
  12. // alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader for instance)
  13. // use the factory to create a Faker\Generator instance
  14. $faker = Faker\Factory::create();
  15. // generate data by accessing properties
  16. echo $faker->name;
  17. // 'Lucy Cechtelar';
  18. echo $faker->address;
  19. // "426 Jordy Lodge
  20. // Cartwrightshire, SC 88120-6700"
  21. echo $faker->text;
  22. // Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi
  23. // beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt
  24. // amet quidem. Iusto deleniti cum autem ad quia aperiam.
  25. // A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui
  26. // quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur
  27. // voluptatem sit aliquam. Dolores voluptatum est.
  28. // Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est.
  29. // Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.
  30. // Et sint et. Ut ducimus quod nemo ab voluptatum.
  31. ```
  32. 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)`.
  33. ```php
  34. <?php
  35. for ($i=0; $i < 10; $i++) {
  36. echo $faker->name, "\n";
  37. }
  38. // Adaline Reichel
  39. // Dr. Santa Prosacco DVM
  40. // Noemy Vandervort V
  41. // Lexi O'Conner
  42. // Gracie Weber
  43. // Roscoe Johns
  44. // Emmett Lebsack
  45. // Keegan Thiel
  46. // Wellington Koelpin II
  47. // Ms. Karley Kiehn V
  48. ```
  49. **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).
  50. ## Formatters
  51. 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.
  52. ### `Faker\Provider\Base`
  53. randomDigit // 7
  54. randomDigitNotNull // 5
  55. randomNumber($nbDigits = NULL) // 79907610
  56. randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932
  57. numberBetween($min = 1000, $max = 9000) // 8567
  58. randomLetter // 'b'
  59. randomElements($array = array ('a','b','c'), $count = 1) // array('c')
  60. randomElement($array = array ('a','b','c')) // 'b'
  61. numerify($string = '###') // '609'
  62. lexify($string = '????') // 'wgts'
  63. bothify($string = '## ??') // '42 jz'
  64. ### `Faker\Provider\Lorem`
  65. word // 'aut'
  66. words($nb = 3) // array('porro', 'sed', 'magni')
  67. sentence($nbWords = 6) // 'Sit vitae voluptas sint non voluptates.'
  68. sentences($nb = 3) // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.')
  69. paragraph($nbSentences = 3) // 'Ut ab voluptas sed a nam. Sint autem inventore aut officia aut aut blanditiis. Ducimus eos odit amet et est ut eum.'
  70. paragraphs($nb = 3) // 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.')
  71. text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.'
  72. ### `Faker\Provider\en_US\Person`
  73. title($gender = null|'male'|'female') // 'Ms.'
  74. titleMale // 'Mr.'
  75. titleFemale // 'Ms.'
  76. suffix // 'Jr.'
  77. name($gender = null|'male'|'female') // 'Dr. Zane Stroman'
  78. firstName($gender = null|'male'|'female') // 'Maynard'
  79. firstNameMale // 'Maynard'
  80. firstNameFemale // 'Rachel'
  81. lastName // 'Zulauf'
  82. ### `Faker\Provider\en_US\Address`
  83. cityPrefix // 'Lake'
  84. secondaryAddress // 'Suite 961'
  85. state // 'NewMexico'
  86. stateAbbr // 'OH'
  87. citySuffix // 'borough'
  88. streetSuffix // 'Keys'
  89. buildingNumber // '484'
  90. city // 'West Judge'
  91. streetName // 'Keegan Trail'
  92. streetAddress // '439 Karley Loaf Suite 897'
  93. postcode // '17916'
  94. address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
  95. country // 'Falkland Islands (Malvinas)'
  96. latitude // '77.147489'
  97. longitude // '86.211205'
  98. ### `Faker\Provider\en_US\PhoneNumber`
  99. phoneNumber // '132-149-0269x3767'
  100. ### `Faker\Provider\en_US\Company`
  101. catchPhrase // 'Monitored regional contingency'
  102. bs // 'e-enable robust architectures'
  103. company // 'Bogan-Treutel'
  104. companySuffix // 'and Sons'
  105. ### `Faker\Provider\en_US\Text`
  106. 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."
  107. ### `Faker\Provider\DateTime`
  108. unixTime($max = 'now') // 58781813
  109. dateTime($max = 'now') // DateTime('2008-04-25 08:37:17')
  110. dateTimeAD($max = 'now') // DateTime('1800-04-29 20:38:49')
  111. iso8601($max = 'now') // '1978-12-09T10:10:29+0000'
  112. date($format = 'Y-m-d', $max = 'now') // '1979-06-09'
  113. time($format = 'H:i:s', $max = 'now') // '20:49:42'
  114. dateTimeBetween($startDate = '-30 years', $endDate = 'now') // DateTime('2003-03-15 02:00:49')
  115. dateTimeThisCentury($max = 'now') // DateTime('1915-05-30 19:28:21')
  116. dateTimeThisDecade($max = 'now') // DateTime('2007-05-29 22:30:48')
  117. dateTimeThisYear($max = 'now') // DateTime('2011-02-27 20:52:14')
  118. dateTimeThisMonth($max = 'now') // DateTime('2011-10-23 13:46:23')
  119. amPm($max = 'now') // 'pm'
  120. dayOfMonth($max = 'now') // '04'
  121. dayOfWeek($max = 'now') // 'Friday'
  122. month($max = 'now') // '06'
  123. monthName($max = 'now') // 'January'
  124. year($max = 'now') // '1993'
  125. century // 'VI'
  126. timezone // 'Europe/Paris'
  127. ### `Faker\Provider\Internet`
  128. email // 'tkshlerin@collins.com'
  129. safeEmail // 'king.alford@example.org'
  130. freeEmail // 'bradley72@gmail.com'
  131. companyEmail // 'russel.durward@mcdermott.org'
  132. freeEmailDomain // 'yahoo.com'
  133. safeEmailDomain // 'example.org'
  134. userName // 'wade55'
  135. domainName // 'wolffdeckow.net'
  136. domainWord // 'feeney'
  137. tld // 'biz'
  138. url // 'http://www.skilesdonnelly.biz/aut-accusantium-ut-architecto-sit-et.html'
  139. slug // 'aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum'
  140. ipv4 // '109.133.32.252'
  141. localIpv4 // '10.242.58.8'
  142. ipv6 // '8e65:933d:22ee:a232:f1c1:2741:1f10:117c'
  143. macAddress // '43:85:B7:08:10:CA'
  144. ### `Faker\Provider\UserAgent`
  145. userAgent // 'Mozilla/5.0 (Windows CE) AppleWebKit/5350 (KHTML, like Gecko) Chrome/13.0.888.0 Safari/5350'
  146. chrome // 'Mozilla/5.0 (Macintosh; PPC Mac OS X 10_6_5) AppleWebKit/5312 (KHTML, like Gecko) Chrome/14.0.894.0 Safari/5312'
  147. firefox // 'Mozilla/5.0 (X11; Linuxi686; rv:7.0) Gecko/20101231 Firefox/3.6'
  148. 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'
  149. opera // 'Opera/8.25 (Windows NT 5.1; en-US) Presto/2.9.188 Version/10.00'
  150. internetExplorer // 'Mozilla/5.0 (compatible; MSIE 7.0; Windows 98; Win 9x 4.90; Trident/3.0)'
  151. ### `Faker\Provider\Payment`
  152. creditCardType // 'MasterCard'
  153. creditCardNumber // '4485480221084675'
  154. creditCardExpirationDate // 04/13
  155. creditCardExpirationDateString // '04/13'
  156. creditCardDetails // array('MasterCard', '4485480221084675', 'Aleksander Nowak', '04/13')
  157. ### `Faker\Provider\Color`
  158. hexcolor // '#fa3cc2'
  159. rgbcolor // '0,255,122'
  160. rgbColorAsArray // array(0,255,122)
  161. rgbCssColor // 'rgb(0,255,122)'
  162. safeColorName // 'fuchsia'
  163. colorName // 'Gainsbor'
  164. ### `Faker\Provider\File`
  165. fileExtension // 'avi'
  166. mimeType // 'video/x-msvideo'
  167. // Copy a random file from the source to the target directory and returns the fullpath or filename
  168. file($sourceDir = '/tmp', $targetDir = '/tmp') // '/path/to/targetDir/13b73edae8443990be1aa8f1a483bc27.jpg'
  169. file($sourceDir, $targetDir, false) // '13b73edae8443990be1aa8f1a483bc27.jpg'
  170. ### `Faker\Provider\Image`
  171. // Image generation provided by LoremPixel (http://lorempixel.com/)
  172. imageUrl($width = 640, $height = 480) // 'http://lorempixel.com/640/480/'
  173. imageUrl($width, $height, 'cats') // 'http://lorempixel.com/800/600/cats/'
  174. image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg'
  175. image($dir, $width, $height, 'cats') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat!
  176. ### `Faker\Provider\Uuid`
  177. uuid // '7e57d004-2b97-0e7a-b45f-5387367791cd'
  178. ### `Faker\Provider\Barcode`
  179. ean13 // '4006381333931'
  180. ean8 // '73513537'
  181. ### `Faker\Provider\Miscellaneous`
  182. boolean($chanceOfGettingTrue = 50) // true
  183. md5 // 'de99a620c50f2990e87144735cd357e7'
  184. sha1 // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'
  185. sha256 // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'
  186. locale // en_UK
  187. countryCode // UK
  188. languageCode // en
  189. ## Unique and Optional modifiers
  190. Faker provides two special providers, `unique()` and `optional()`, to be called before any provider. `optional()` can be useful for seeding non-required fields, like a mobile telephone number; `unique()` is required to populate fields that cannot accept twice the same value, like primary identifiers.
  191. ```php
  192. // unique() forces providers to return unique values
  193. $values = array();
  194. for ($i=0; $i < 10; $i++) {
  195. // get a random digit, but always a new one, to avoid duplicates
  196. $values []= $faker->unique()->randomDigit;
  197. }
  198. print_r($values); // [4, 1, 8, 5, 0, 2, 6, 9, 7, 3]
  199. // providers with a limited range will throw an exception when no new unique value can be generated
  200. $values = array();
  201. try {
  202. for ($i=0; $i < 10; $i++) {
  203. $values []= $faker->unique()->randomDigitNotNull;
  204. }
  205. } catch (\OverflowException $e) {
  206. echo "There are only 9 unique digits not null, Faker can't generate 10 of them!";
  207. }
  208. // you can reset the unique modifier for all providers by passing true as first argument
  209. $faker->unique($reset = true)->randomDigitNotNull; // will not throw OverflowException since unique() was reset
  210. // tip: unique() keeps one array of values per provider
  211. // optional() sometimes bypasses the provider to return a default value instead (which defaults to NULL)
  212. $values = array();
  213. for ($i=0; $i < 10; $i++) {
  214. // get a random digit, but also null sometimes
  215. $values []= $faker->optional()->randomDigit;
  216. }
  217. print_r($values); // [1, 4, null, 9, 5, null, null, 4, 6, null]
  218. // optional() accepts a weight argument to specify the probability of receiving the default value.
  219. // 0 will always return the default value; 1 will always return the provider. Default weight is 0.5.
  220. $faker->optional($weight = 0.1)->randomDigit; // 90% chance of NULL
  221. $faker->optional($weight = 0.9)->randomDigit; // 10% chance of NULL
  222. // optional() accepts a default argument to specify the default value to return.
  223. // Defaults to NULL.
  224. $faker->optional($weight = 0.5, $default = false)->randomDigit; // 50% chance of FALSE
  225. $faker->optional($weight = 0.9, $default = 'abc')->word; // 10% chance of 'abc'
  226. ```
  227. ## Localization
  228. `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).
  229. ```php
  230. <?php
  231. $faker = Faker\Factory::create('fr_FR'); // create a French faker
  232. for ($i=0; $i < 10; $i++) {
  233. echo $faker->name, "\n";
  234. }
  235. // Luce du Coulon
  236. // Auguste Dupont
  237. // Roger Le Voisin
  238. // Alexandre Lacroix
  239. // Jacques Humbert-Roy
  240. // Thérèse Guillet-Andre
  241. // Gilles Gros-Bodin
  242. // Amélie Pires
  243. // Marcel Laporte
  244. // Geneviève Marchal
  245. ```
  246. 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!
  247. ## Populating Entities Using an ORM or an ODM
  248. Faker provides adapters for Object-Relational and Object-Document Mappers (currently, [Propel](http://www.propelorm.org), [Doctrine2](http://www.doctrine-project.org/projects/orm/2.0/docs/en), 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).
  249. 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.
  250. Here is an example showing how to populate 5 `Author` and 10 `Book` objects:
  251. ```php
  252. <?php
  253. $generator = \Faker\Factory::create();
  254. $populator = new Faker\ORM\Propel\Populator($generator);
  255. $populator->addEntity('Author', 5);
  256. $populator->addEntity('Book', 10);
  257. $insertedPKs = $populator->execute();
  258. ```
  259. 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()`:
  260. ```php
  261. <?php
  262. $populator->addEntity('Book', 5, array(
  263. 'ISBN' => function() use ($generator) { return $generator->randomNumber(13); }
  264. ));
  265. ```
  266. In this example, Faker will guess a formatter for all columns except `ISBN`, for which the given anonymous function will be used.
  267. **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:
  268. ```php
  269. <?php
  270. $populator->addEntity('Book', 5, array(
  271. 'CreatedAt' => null,
  272. 'UpdatedAt' => null,
  273. ));
  274. ```
  275. 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:
  276. ```php
  277. <?php
  278. print_r($insertedPKs);
  279. // array(
  280. // 'Author' => (34, 35, 36, 37, 38),
  281. // 'Book' => (456, 457, 458, 459, 470, 471, 472, 473, 474, 475)
  282. // )
  283. ```
  284. 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.
  285. Lastly, if you want to execute an arbitrary function on an entity before insertion, use the fourth argument of the `addEntity()` method:
  286. ```php
  287. <?php
  288. $populator->addEntity('Book', 5, array(), array(
  289. function($book) { $book->publish(); },
  290. ));
  291. ```
  292. ## Seeding the Generator
  293. 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.
  294. ```php
  295. <?php
  296. $faker = Faker\Factory::create();
  297. $faker->seed(1234);
  298. echo $faker->name; // 'Jess Mraz I';
  299. ```
  300. > **Tip**: DateTime formatters won't reproduce the same fake data if you don't fix the `$max` value:
  301. >
  302. > ```php
  303. > <?php
  304. > // even when seeded, this line will return different results because $max varies
  305. > $faker->dateTime(); // equivalent to $faker->dateTime($max = 'now')
  306. > // make sure you fix the $max parameter
  307. > $faker->dateTime('2014-02-25 08:37:17'); // will return always the same date when seeded
  308. ## Faker Internals: Understanding Providers
  309. 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:
  310. ```php
  311. <?php
  312. $faker = new Faker\Generator();
  313. $faker->addProvider(new Faker\Provider\en_US\Person($faker));
  314. $faker->addProvider(new Faker\Provider\en_US\Address($faker));
  315. $faker->addProvider(new Faker\Provider\en_US\PhoneNumber($faker));
  316. $faker->addProvider(new Faker\Provider\en_US\Company($faker));
  317. $faker->addProvider(new Faker\Provider\Lorem($faker));
  318. $faker->addProvider(new Faker\Provider\Internet($faker));
  319. ````
  320. 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.
  321. 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.
  322. Here is an example provider for populating Book data:
  323. ```php
  324. <?php
  325. namespace Faker\Provider;
  326. class Book extends \Faker\Provider\Base
  327. {
  328. public function title($nbWords = 5)
  329. {
  330. $sentence = $this->generator->sentence($nbWords);
  331. return substr($sentence, 0, strlen($sentence) - 1);
  332. }
  333. public function ISBN()
  334. {
  335. return $this->generator->randomNumber(13);
  336. }
  337. }
  338. ```
  339. To register this provider, just add a new instance of `\Faker\Provider\Book` to an existing generator:
  340. ```php
  341. <?php
  342. $faker->addProvider(new \Faker\Provider\Book($faker));
  343. ```
  344. Now you can use the two new formatters like any other Faker formatter:
  345. ```php
  346. <?php
  347. $book = new Book();
  348. $book->setTitle($faker->title);
  349. $book->setISBN($faker->ISBN);
  350. $book->setSummary($faker->text);
  351. $book->setPrice($faker->randomNumber(2));
  352. ```
  353. **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.
  354. ## Real Life Usage
  355. The following script generates a valid XML document:
  356. ```php
  357. <?php
  358. require_once '/path/to/Faker/src/autoload.php';
  359. $faker = Faker\Factory::create();
  360. ?>
  361. <?xml version="1.0" encoding="UTF-8"?>
  362. <contacts>
  363. <?php for ($i=0; $i < 10; $i++): ?>
  364. <contact firstName="<?php echo $faker->firstName ?>" lastName="<?php echo $faker->lastName ?>" email="<?php echo $faker->email ?>"/>
  365. <phone number="<?php echo $faker->phoneNumber ?>"/>
  366. <?php if ($faker->boolean(25)): ?>
  367. <birth date="<?php echo $faker->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $faker->city ?>"/>
  368. <?php endif; ?>
  369. <address>
  370. <street><?php echo $faker->streetAddress ?></street>
  371. <city><?php echo $faker->city ?></city>
  372. <postcode><?php echo $faker->postcode ?></postcode>
  373. <state><?php echo $faker->state ?></state>
  374. </address>
  375. <company name="<?php echo $faker->company ?>" catchPhrase="<?php echo $faker->catchPhrase ?>">
  376. <?php if ($faker->boolean(33)): ?>
  377. <offer><?php echo $faker->bs ?></offer>
  378. <?php endif; ?>
  379. <?php if ($faker->boolean(33)): ?>
  380. <director name="<?php echo $faker->name ?>" />
  381. <?php endif; ?>
  382. </company>
  383. <?php if ($faker->boolean(15)): ?>
  384. <details>
  385. <![CDATA[
  386. <?php echo $faker->text(400) ?>
  387. ]]>
  388. </details>
  389. <?php endif; ?>
  390. </contact>
  391. <?php endfor; ?>
  392. </contacts>
  393. ```
  394. Running this script produces a document looking like:
  395. ```xml
  396. <?xml version="1.0" encoding="UTF-8"?>
  397. <contacts>
  398. <contact firstName="Ona" lastName="Bednar" email="schamberger.frank@wuckert.com"/>
  399. <phone number="1-265-479-1196x714"/>
  400. <address>
  401. <street>182 Harrison Cove</street>
  402. <city>North Lloyd</city>
  403. <postcode>45577</postcode>
  404. <state>Alabama</state>
  405. </address>
  406. <company name="Veum, Funk and Shanahan" catchPhrase="Function-based stable solution">
  407. <offer>orchestrate compelling web-readiness</offer>
  408. </company>
  409. <details>
  410. <![CDATA[
  411. Alias accusantium voluptatum autem nobis cumque neque modi. Voluptatem error molestiae consequatur alias.
  412. Illum commodi molestiae aut repellat id. Et sit consequuntur aut et ullam asperiores. Cupiditate culpa voluptatem et mollitia dolor. Nisi praesentium qui ut.
  413. ]]>
  414. </details>
  415. </contact>
  416. <contact firstName="Aurelie" lastName="Paucek" email="alfonzo55@durgan.com"/>
  417. <phone number="863.712.1363x9425"/>
  418. <address>
  419. <street>90111 Hegmann Inlet</street>
  420. <city>South Geovanymouth</city>
  421. <postcode>69961-9311</postcode>
  422. <state>Colorado</state>
  423. </address>
  424. <company name="Krajcik-Grimes" catchPhrase="Switchable cohesive instructionset">
  425. </company>
  426. </contact>
  427. <contact firstName="Clifton" lastName="Kshlerin" email="kianna.wiegand@framiwyman.info"/>
  428. <phone number="692-194-4746"/>
  429. <address>
  430. <street>9791 Nona Corner</street>
  431. <city>Harberhaven</city>
  432. <postcode>74062-8191</postcode>
  433. <state>RhodeIsland</state>
  434. </address>
  435. <company name="Rosenbaum-Aufderhar" catchPhrase="Realigned asynchronous encryption">
  436. </company>
  437. </contact>
  438. <contact firstName="Alexandre" lastName="Orn" email="thelma37@erdmancorwin.biz"/>
  439. <phone number="189.655.8677x027"/>
  440. <address>
  441. <street>11161 Schultz Via</street>
  442. <city>Feilstad</city>
  443. <postcode>98019</postcode>
  444. <state>NewJersey</state>
  445. </address>
  446. <company name="O'Hara-Prosacco" catchPhrase="Re-engineered solution-oriented algorithm">
  447. <director name="Dr. Berenice Auer V" />
  448. </company>
  449. <details>
  450. <![CDATA[
  451. Ut itaque et quaerat doloremque eum praesentium. Rerum in saepe dolorem. Explicabo qui consequuntur commodi minima rem.
  452. Harum temporibus rerum dolores. Non molestiae id dolorem placeat.
  453. Aut asperiores nihil eius repellendus. Vero nihil corporis voluptatem explicabo commodi. Occaecati omnis blanditiis beatae quod aspernatur eos.
  454. ]]>
  455. </details>
  456. </contact>
  457. <contact firstName="Katelynn" lastName="Kohler" email="reinger.trudie@stiedemannjakubowski.com"/>
  458. <phone number="(665)713-1657"/>
  459. <address>
  460. <street>6106 Nader Village Suite 753</street>
  461. <city>McLaughlinstad</city>
  462. <postcode>43189-8621</postcode>
  463. <state>Missouri</state>
  464. </address>
  465. <company name="Herman-Tremblay" catchPhrase="Object-based explicit service-desk">
  466. <offer>expedite viral synergies</offer>
  467. <director name="Arden Deckow" />
  468. </company>
  469. </contact>
  470. <contact firstName="Blanca" lastName="Stark" email="tad27@feest.net"/>
  471. <phone number="168.719.4692x87177"/>
  472. <address>
  473. <street>7546 Kuvalis Plaza</street>
  474. <city>South Wilfrid</city>
  475. <postcode>77069</postcode>
  476. <state>Georgia</state>
  477. </address>
  478. <company name="Upton, Braun and Rowe" catchPhrase="Visionary leadingedge pricingstructure">
  479. </company>
  480. </contact>
  481. <contact firstName="Rene" lastName="Spencer" email="anibal28@armstrong.info"/>
  482. <phone number="715.222.0095x175"/>
  483. <birth date="2008-08-07" place="Zulaufborough"/>
  484. <address>
  485. <street>478 Daisha Landing Apt. 510</street>
  486. <city>West Lizethhaven</city>
  487. <postcode>30566-5362</postcode>
  488. <state>WestVirginia</state>
  489. </address>
  490. <company name="Wiza Inc" catchPhrase="Persevering reciprocal approach">
  491. <offer>orchestrate dynamic networks</offer>
  492. <director name="Erwin Nienow" />
  493. </company>
  494. <details>
  495. <![CDATA[
  496. Dolorem consequatur voluptates unde optio unde. Accusantium dolorem est est architecto impedit. Corrupti et provident quo.
  497. Reprehenderit dolores aut quidem suscipit repudiandae corporis error. Molestiae enim aperiam illo.
  498. Et similique qui non expedita quia dolorum. Ex rem incidunt ea accusantium temporibus minus non.
  499. ]]>
  500. </details>
  501. </contact>
  502. <contact firstName="Alessandro" lastName="Hagenes" email="tbreitenberg@oharagorczany.com"/>
  503. <phone number="1-284-958-6768"/>
  504. <address>
  505. <street>1251 Koelpin Mission</street>
  506. <city>North Revastad</city>
  507. <postcode>81620</postcode>
  508. <state>Maryland</state>
  509. </address>
  510. <company name="Stiedemann-Bruen" catchPhrase="Re-engineered 24/7 success">
  511. </company>
  512. </contact>
  513. <contact firstName="Novella" lastName="Rutherford" email="claud65@bogisich.biz"/>
  514. <phone number="(091)825-7971"/>
  515. <address>
  516. <street>6396 Langworth Hills Apt. 446</street>
  517. <city>New Carlos</city>
  518. <postcode>89399-0268</postcode>
  519. <state>Wyoming</state>
  520. </address>
  521. <company name="Stroman-Legros" catchPhrase="Expanded 4thgeneration moratorium">
  522. <director name="Earlene Bayer" />
  523. </company>
  524. </contact>
  525. <contact firstName="Andreane" lastName="Mann" email="meggie17@ornbaumbach.com"/>
  526. <phone number="941-659-9982x5689"/>
  527. <birth date="1934-02-21" place="Stantonborough"/>
  528. <address>
  529. <street>2246 Kreiger Station Apt. 291</street>
  530. <city>Kaydenmouth</city>
  531. <postcode>11397-1072</postcode>
  532. <state>Wyoming</state>
  533. </address>
  534. <company name="Lebsack, Bernhard and Kiehn" catchPhrase="Persevering actuating framework">
  535. <offer>grow sticky portals</offer>
  536. </company>
  537. <details>
  538. <![CDATA[
  539. 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.
  540. Fugiat non in itaque sunt nobis totam. Sed nesciunt est deleniti cumque alias. Repudiandae quo aut numquam modi dicta libero.
  541. ]]>
  542. </details>
  543. </contact>
  544. </contacts>
  545. ```
  546. ## Language specific formatters
  547. ### `Faker\Provider\cs_CZ\Address`
  548. ```php
  549. <?php
  550. echo $faker->region; // "Liberecký kraj"
  551. ```
  552. ### `Faker\Provider\cs_CZ\Company`
  553. ```php
  554. <?php
  555. // Generates a valid IČO
  556. echo $faker->ico; // "69663963"
  557. ```
  558. ### `Faker\Provider\cs_CZ\DateTime`
  559. ```php
  560. <?php
  561. echo $faker->monthNameGenitive; // "prosince"
  562. echo $faker->formattedDate; // "12. listopadu 2015"
  563. ```
  564. ### `Faker\Provider\da_DK\Person`
  565. ```php
  566. <?php
  567. // Generates a random CPR number
  568. echo $faker->cpr; // "051280-2387"
  569. ```
  570. ### `Faker\Provider\da_DK\Address`
  571. ```php
  572. <?php
  573. // Generates a random 'kommune' name
  574. echo $faker->kommune; // "Frederiksberg"
  575. // Generates a random region name
  576. echo $faker->region; // "Region Sjælland"
  577. ```
  578. ### `Faker\Provider\da_DK\Company`
  579. ```php
  580. <?php
  581. // Generates a random CVR number
  582. echo $faker->cvr; // "32458723"
  583. // Generates a random P number
  584. echo $faker->p; // "5398237590"
  585. ```
  586. ### `Faker\Provider\fr_FR\Company`
  587. ```php
  588. <?php
  589. // Generates a random SIREN number
  590. echo $faker->siren; // 082 250 104
  591. // Generates a random SIRET number
  592. echo $faker->siret; // 347 355 708 00224
  593. // Generates a random SIRET number (controlling the number of sequential digits)
  594. echo $faker->siret(3); // 438 472 611 01513
  595. ```
  596. ### `Faker\Provider\fr_FR\Address`
  597. ```php
  598. <?php
  599. // Generates a random department name
  600. echo $faker->departmentName; // "Haut-Rhin"
  601. // Generates a random department number
  602. echo $faker->departmentNumber; // "2B"
  603. // Generates a random department info (department number => department name)
  604. $faker->department; // array('18' => 'Cher');
  605. // Generates a random region
  606. echo $faker->region; // "Saint-Pierre-et-Miquelon"
  607. ```
  608. ### `Faker\Provider\ja_JP\Person`
  609. ```php
  610. <?php
  611. // Generates a 'kana' name
  612. echo $faker->kanaName; // "アオタ ナオコ"
  613. // Generates a 'kana' first name
  614. echo $faker->firstKanaName; // "トモミ"
  615. // Generates a 'kana' last name
  616. echo $faker->lastKanaName; // "ナギサ"
  617. ```
  618. ### `Faker\Provider\pl_PL\Person`
  619. ```php
  620. <?php
  621. // Generates a random PESEL number
  622. echo $faker->pesel; // "40061451555"
  623. // Generates a random personal identity card number
  624. echo $faker->personalIdentityNumber; // "AKX383360"
  625. // Generates a random taxpayer identification number (NIP)
  626. echo $faker->taxpayerIdentificationNumber; // '8211575109'
  627. ```
  628. ### `Faker\Provider\pl_PL\Company`
  629. ```php
  630. <?php
  631. // Generates a random REGON number
  632. echo $faker->regon; // "714676680"
  633. // Generates a random local REGON number
  634. echo $faker->regonLocal; // "15346111382836"
  635. ```
  636. ### `Faker\Provider\pl_PL\Payment`
  637. ```php
  638. <?php
  639. // Generates a random bank name
  640. echo $faker->bank; // "Narodowy Bank Polski"
  641. // Generates a random bank account number
  642. echo $faker->bankAccountNumber; // "PL14968907563953822118075816"
  643. ```
  644. ### `Faker\Provider\pt_PT\Person`
  645. ```php
  646. <?php
  647. // Generates a random taxpayer identification number (in portuguese - Número de Identificação Fiscal NIF)
  648. echo $faker->taxpayerIdentificationNumber; // '165249277'
  649. ```
  650. ### `Faker\Provider\ro_RO\Person`
  651. ```php
  652. <?php
  653. // Generates a random male name prefix/title
  654. echo $faker->prefixMale; // "ing."
  655. // Generates a random female name prefix/title
  656. echo $faker->prefixFemale; // "d-na."
  657. // Generates a random male fist name
  658. echo $faker->firstNameMale; // "Adrian"
  659. // Generates a random female fist name
  660. echo $faker->firstNameFemale; // "Miruna"
  661. // Generates a random Personal Numerical Code (CNP)
  662. echo $faker->cnp; // "2800523081231"
  663. echo $faker->cnp($gender = NULL, $century = NULL, $county = NULL);
  664. // Valid option values:
  665. // $gender: m, f, 1, 2
  666. // $century: 1800, 1900, 2000, 1, 2, 3, 4, 5, 6
  667. // $county: 2 letter ISO 3166-2:RO county codes and B1-B6 for Bucharest's 6 sectors
  668. ```
  669. ### `Faker\Provider\ro_RO\PhoneNumber`
  670. ```php
  671. <?php
  672. // Generates a random toll-free phone number
  673. echo $faker->tollFreePhoneNumber; // "0800123456"
  674. // Generates a random premium-rate phone number
  675. echo $faker->premiumRatePhoneNumber; // "0900123456"
  676. ```
  677. ## License
  678. Faker is released under the MIT Licence. See the bundled LICENSE file for details.