mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-01-17 14:18:29 +01:00
parent
226257de22
commit
278660f004
24
readme.md
24
readme.md
@ -38,13 +38,27 @@ echo $faker->lorem;
|
||||
|
||||
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\Internet`
|
||||
|
||||
domainName() // 'mueller.info'
|
||||
domainWord() // 'von'
|
||||
email() // 'cshields@rosenbaum.com'
|
||||
freeEmail() // 'dayna55@gmail.com'
|
||||
freeEmailDomain() // 'yahoo.com'
|
||||
ipv4() // '237.149.115.38'
|
||||
ipv6() // '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1'
|
||||
safeEmail() // 'nbatz@example.org'
|
||||
tld() // 'info'
|
||||
url() // 'http://www.runolfsdottir.com/'
|
||||
userName() // 'tremblay.haylie'
|
||||
|
||||
### `Faker\Provider\Lorem`
|
||||
|
||||
lorem() // 'Fuga totam reiciendis qui architecto fugiat. (...) Voluptas optio quos sed.'
|
||||
lorem() // 'Fuga totam reiciendis qui architecto fugiat. (...)'
|
||||
paragraph() // 'Sed a nam et sint autem. Aut officia aut. Blanditiis et ducimus.'
|
||||
paragraphs() // array('Amet et est.', (...) 'Rerum exercitationem est.')
|
||||
paragraphs() // array('Amet et est. (...)', 'Sequi cum culpa rem. Rerum exercitationem est.')
|
||||
sentence() // 'Sit vitae voluptas sint non.'
|
||||
sentences() // array('Ut optio quos qui illo error nihil.', ('Vero a officia id corporis incidunt.' (...), 'Provident esse hic eligendi quos culpa ut.')
|
||||
sentences() // array('Ut optio quos qui illo error nihil.', 'Vero a officia id corporis incidunt.', 'Provident esse hic eligendi quos culpa ut.')
|
||||
word() // 'aut'
|
||||
words() // array('porro', 'sed', 'magni')
|
||||
|
||||
@ -81,8 +95,8 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
|
||||
|
||||
### `Faker\Provider\en_US\PhoneNumber`
|
||||
|
||||
phoneNumber() // '132-149-0269x3767'
|
||||
|
||||
phoneNumber() // '132-149-0269x3767'
|
||||
|
||||
## Localization
|
||||
|
||||
`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.
|
||||
|
@ -8,7 +8,7 @@ class Factory
|
||||
{
|
||||
const DEFAULT_LOCALE = 'en_US';
|
||||
|
||||
protected static $defaultProviders = array('Name', 'Address', 'PhoneNumber', 'Company', 'Lorem');
|
||||
protected static $defaultProviders = array('Name', 'Address', 'PhoneNumber', 'Company', 'Lorem', 'Internet');
|
||||
|
||||
public static function create($locale = self::DEFAULT_LOCALE)
|
||||
{
|
||||
|
126
src/Provider/Internet.php
Normal file
126
src/Provider/Internet.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Provider;
|
||||
|
||||
require_once __DIR__ . '/Base.php';
|
||||
|
||||
class Internet extends \Faker\Provider\Base
|
||||
{
|
||||
protected static $safeEmailTld = array('org', 'com', 'net');
|
||||
protected static $freeEmailDomain = array('gmail.com', 'yahoo.com', 'hotmail.com');
|
||||
protected static $tld = array('com', 'com', 'com', 'com', 'com', 'com', 'biz', 'info', 'net', 'org');
|
||||
|
||||
protected static $userNameFormats = array(
|
||||
'{{lastName}}.{{firstName}}',
|
||||
'{{firstName}}.{{lastName}}',
|
||||
'{{firstName}}##',
|
||||
'?{{lastName}}',
|
||||
);
|
||||
protected static $emailFormats = array(
|
||||
'{{userName}}@{{domainName}}',
|
||||
);
|
||||
protected static $urlFormats = array(
|
||||
'http://www.{{domainName}}/',
|
||||
'http://{{domainName}}/',
|
||||
);
|
||||
|
||||
/**
|
||||
* @example 'jdoe@acme.biz'
|
||||
*/
|
||||
public function email()
|
||||
{
|
||||
$format = static::randomElement(static::$emailFormats);
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'jdoe@example.com'
|
||||
*/
|
||||
public function safeEmail()
|
||||
{
|
||||
return $this->userName() . '@example.' . static::randomElement(static::$safeEmailTld);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'jdoe@gmail.com'
|
||||
*/
|
||||
public function freeEmail()
|
||||
{
|
||||
return $this->userName() . '@' . static::freeEmailDomain();
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'gmail.com'
|
||||
*/
|
||||
public static function freeEmailDomain()
|
||||
{
|
||||
return static::randomElement(static::$freeEmailDomain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'jdoe'
|
||||
*/
|
||||
public function userName()
|
||||
{
|
||||
$format = static::randomElement(static::$userNameFormats);
|
||||
return strtolower(static::bothify($this->generator->parse($format)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'tiramisu.com'
|
||||
*/
|
||||
public function domainName()
|
||||
{
|
||||
return $this->domainWord() . '.' . $this->tld();
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'faber'
|
||||
*/
|
||||
public function domainWord()
|
||||
{
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
|
||||
return strtolower($company);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'com'
|
||||
*/
|
||||
public function tld()
|
||||
{
|
||||
return static::randomElement(static::$tld);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example 'http://www.runolfsdottir.com/'
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
$format = static::randomElement(static::$urlFormats);
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '237.149.115.38'
|
||||
*/
|
||||
public function ipv4()
|
||||
{
|
||||
return long2ip(mt_rand(0, "4294967295"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1'
|
||||
*/
|
||||
public function ipv6()
|
||||
{
|
||||
$res = array();
|
||||
for ($i=0; $i < 8; $i++) {
|
||||
$res []= dechex(mt_rand(0, "65535"));
|
||||
}
|
||||
return join(':', $res);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ $generator = Faker\Factory::create();
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<contacts>
|
||||
<?php for ($i=0; $i < 10; $i++): ?>
|
||||
<contact firstName="<?php echo $generator->firstName ?>" lastName="<?php echo $generator->lastName ?>">
|
||||
<contact firstName="<?php echo $generator->firstName ?>" lastName="<?php echo $generator->lastName ?>" email="<?php echo $generator->email ?>"/>
|
||||
<phone number="<?php echo $generator->phoneNumber ?>"/>
|
||||
<?php if (mt_rand(0,5) == 0): ?>
|
||||
<countryOfBirth><?php echo $generator->address ?></countryOfBirth>
|
||||
@ -21,7 +21,7 @@ $generator = Faker\Factory::create();
|
||||
<offer><?php echo $generator->bs ?></offer>
|
||||
<?php endif; ?>
|
||||
<?php if (mt_rand(0,3) == 0): ?>
|
||||
<director name="<?php echo $generator->name ?>"/>
|
||||
<director name="<?php echo $generator->name ?>" />
|
||||
<?php endif; ?>
|
||||
</company>
|
||||
<?php if (mt_rand(0,5) == 0): ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user