fzaninotto/Faker

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.

Faker is heavily inspired by Perl’s Data::Faker, and by ruby’s Faker.

Faker requires PHP >= 5.3.3.

Table of Contents
Installation
Basic Usage
Formatters
Base
Lorem Ipsum Text
Person
Address
Phone Number
Company
Real Text
Date and Time
Internet
User Agent
Payment
Color
File
Image
Uuid
Barcode
Miscellaneous
Biased
Html Lorem
Modifiers
Localization
Populating Entities Using an ORM or an ODM
Seeding the Generator
Faker Internals: Understanding Providers
Real Life Usage
Language specific formatters
Third-Party Libraries Extending/Based On Faker
License
Installation
composer require fzaninotto/faker
Basic Usage
Autoloading
Faker supports both PSR-0 as PSR-4 autoloaders.

<?php # When installed via composer require_once 'vendor/autoload.php'; You can also load Fakers shipped PSR-0 autoloader <?php # Load Fakers own autoloader require_once '/path/to/Faker/src/autoload.php'; alternatively, you can use any another PSR-4 compliant autoloader Create fake data 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. <?php // use the factory to create a Faker\Generator instance $faker = Faker\Factory::create(); // generate data by accessing properties echo $faker->name; // 'Lucy Cechtelar'; echo $faker->address; // "426 Jordy Lodge // Cartwrightshire, SC 88120-6700" echo $faker->text; // Dolores sit sint laboriosam dolorem culpa et autem. Beatae nam sunt fugit // et sit et mollitia sed. // Fuga deserunt tempora facere magni omnis. Omnis quia temporibus laudantium // sit minima sint. 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). <?php for ($i = 0; $i < 10; $i++) { echo $faker->name, "\n"; } // Adaline Reichel // Dr. Santa Prosacco DVM // Noemy Vandervort V // Lexi O'Conner // Gracie Weber // Roscoe Johns // Emmett Lebsack // Keegan Thiel // Wellington Koelpin II // Ms. Karley Kiehn V Tip: For a quick generation of fake data, you can also use Faker as a command line tool thanks to faker-cli. Formatters 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. Faker\Provider\Base randomDigit // 7 randomDigitNot(5) // 0, 1, 2, 3, 4, 6, 7, 8, or 9 randomDigitNotNull // 5 randomNumber($nbDigits = NULL, $strict = false) // 79907610 randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL) // 48.8932 numberBetween($min = 1000, $max = 9000) // 8567 randomLetter // 'b' // returns randomly ordered subsequence of a provided array randomElements($array = array ('a','b','c'), $count = 1) // array('c') randomElement($array = array ('a','b','c')) // 'b' shuffle('hello, world') // 'rlo,h eoldlw' shuffle(array(1, 2, 3)) // array(2, 1, 3) numerify('Hello ###') // 'Hello 609' lexify('Hello ???') // 'Hello wgt' bothify('Hello ##??') // 'Hello 42jz' asciify('Hello ***') // 'Hello R6+' regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej Faker\Provider\Lorem word // 'aut' words($nb = 3, $asText = false) // array('porro', 'sed', 'magni') sentence($nbWords = 6, $variableNbWords = true) // 'Sit vitae voluptas sint non voluptates.' sentences($nb = 3, $asText = false) // array('Optio quos qui illo error.', 'Laborum vero a officia id corporis.', 'Saepe provident esse hic eligendi.') 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.' 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.') text($maxNbChars = 200) // 'Fuga totam reiciendis qui architecto fugiat nemo. Consequatur recusandae qui cupiditate eos quod.' Faker\Provider\en_US\Person title($gender = null|'male'|'female') // 'Ms.' titleMale // 'Mr.' titleFemale // 'Ms.' suffix // 'Jr.' name($gender = null|'male'|'female') // 'Dr. Zane Stroman' firstName($gender = null|'male'|'female') // 'Maynard' firstNameMale // 'Maynard' firstNameFemale // 'Rachel' lastName // 'Zulauf' Faker\Provider\en_US\Address cityPrefix // 'Lake' secondaryAddress // 'Suite 961' state // 'NewMexico' stateAbbr // 'OH' citySuffix // 'borough' streetSuffix // 'Keys' buildingNumber // '484' city // 'West Judge' streetName // 'Keegan Trail' streetAddress // '439 Karley Loaf Suite 897' postcode // '17916' address // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473' country // 'Falkland Islands (Malvinas)' latitude($min = -90, $max = 90) // 77.147489 longitude($min = -180, $max = 180) // 86.211205 Faker\Provider\en_US\PhoneNumber phoneNumber // '201-886-0269 x3767' tollFreePhoneNumber // '(888) 937-7238' e164PhoneNumber // '+27113456789' Faker\Provider\en_US\Company catchPhrase // 'Monitored regional contingency' bs // 'e-enable robust architectures' company // 'Bogan-Treutel' companySuffix // 'and Sons' jobTitle // 'Cashier' Faker\Provider\en_US\Text 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." Faker\Provider\DateTime unixTime($max = 'now') // 58781813 dateTime($max = 'now', $timezone = null) // DateTime('2008-04-25 08:37:17', 'UTC') dateTimeAD($max = 'now', $timezone = null) // DateTime('1800-04-29 20:38:49', 'Europe/Paris') iso8601($max = 'now') // '1978-12-09T10:10:29+0000' date($format = 'Y-m-d', $max = 'now') // '1979-06-09' time($format = 'H:i:s', $max = 'now') // '20:49:42' dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = null) // DateTime('2003-03-15 02:00:49', 'Africa/Lagos') dateTimeInInterval($startDate = '-30 years', $interval = '+ 5 days', $timezone = null) // DateTime('2003-03-15 02:00:49', 'Antartica/Vostok') dateTimeThisCentury($max = 'now', $timezone = null) // DateTime('1915-05-30 19:28:21', 'UTC') dateTimeThisDecade($max = 'now', $timezone = null) // DateTime('2007-05-29 22:30:48', 'Europe/Paris') dateTimeThisYear($max = 'now', $timezone = null) // DateTime('2011-02-27 20:52:14', 'Africa/Lagos') dateTimeThisMonth($max = 'now', $timezone = null) // DateTime('2011-10-23 13:46:23', 'Antarctica/Vostok') amPm($max = 'now') // 'pm' dayOfMonth($max = 'now') // '04' dayOfWeek($max = 'now') // 'Friday' month($max = 'now') // '06' monthName($max = 'now') // 'January' year($max = 'now') // '1993' century // 'VI' timezone // 'Europe/Paris'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值