mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-22 08:19:52 +01:00
Separate base providers to ease localization
This commit is contained in:
parent
0d1ee8c09d
commit
5285b1a9d4
84
src/Provider/Base/Address.php
Normal file
84
src/Provider/Base/Address.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Provider\Base;
|
||||
|
||||
class Address
|
||||
{
|
||||
protected static $citySuffix = array('Ville');
|
||||
protected static $cityFormats = array(
|
||||
'{{firstName}}{{citySuffix}}',
|
||||
);
|
||||
protected static $streetNameFormats = array(
|
||||
'{{lastName}} {{streetSuffix}}'
|
||||
);
|
||||
protected static $streetAddressFormats = array(
|
||||
'{{buildingNumber}} {{streetName}}'
|
||||
);
|
||||
protected static $addressFormats = array(
|
||||
'{{streetAddress}} {{postcode}} {{city}}',
|
||||
);
|
||||
|
||||
protected static $buildingNumber = array('##');
|
||||
protected static $streetSuffix = array('Street');
|
||||
protected static $postcode = array('#####');
|
||||
protected static $country = array();
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public static function citySuffix()
|
||||
{
|
||||
return static::$citySuffix[array_rand(static::$citySuffix)];
|
||||
}
|
||||
|
||||
public static function streetSuffix()
|
||||
{
|
||||
return static::$streetSuffix[array_rand(static::$streetSuffix)];
|
||||
}
|
||||
|
||||
public function buildingNumber()
|
||||
{
|
||||
$format = static::$buildingNumber[array_rand(static::$buildingNumber)];
|
||||
return $this->generator->numerify($format);
|
||||
}
|
||||
|
||||
public function city()
|
||||
{
|
||||
$format = static::$cityFormats[array_rand(static::$cityFormats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public function streetName()
|
||||
{
|
||||
$format = static::$streetNameFormats[array_rand(static::$streetNameFormats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public function streetAddress()
|
||||
{
|
||||
$format = static::$streetAddressFormats[array_rand(static::$streetAddressFormats)];
|
||||
return $this->generator->numerify($this->generator->parse($format));
|
||||
}
|
||||
|
||||
public function postcode()
|
||||
{
|
||||
$format = static::$postcode[array_rand(static::$postcode)];
|
||||
return $this->generator->numerify($format);
|
||||
}
|
||||
|
||||
public function address()
|
||||
{
|
||||
$format = static::$addressFormats[array_rand(static::$addressFormats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public static function country()
|
||||
{
|
||||
return static::$country[array_rand(static::$country)];
|
||||
}
|
||||
|
||||
}
|
31
src/Provider/Base/Company.php
Normal file
31
src/Provider/Base/Company.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Provider\Base;
|
||||
|
||||
class Company
|
||||
{
|
||||
protected static $formats = array(
|
||||
'{{lastName}} {{companySuffix}}',
|
||||
);
|
||||
|
||||
protected static $companySuffix = array('Ltd');
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
$format = static::$formats[array_rand(static::$formats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public function companySuffix()
|
||||
{
|
||||
return static::$companySuffix[array_rand(static::$companySuffix)];;
|
||||
}
|
||||
|
||||
}
|
38
src/Provider/Base/Name.php
Normal file
38
src/Provider/Base/Name.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Provider\Base;
|
||||
|
||||
class Name
|
||||
{
|
||||
protected static $formats = array(
|
||||
'{{firstName}} {{lastName}}',
|
||||
);
|
||||
|
||||
protected static $firstName = array('John', 'Jane');
|
||||
|
||||
protected static $lastName = array('Doe');
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function name()
|
||||
{
|
||||
$format = static::$formats[array_rand(static::$formats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public static function firstName()
|
||||
{
|
||||
return static::$firstName[array_rand(static::$firstName)];
|
||||
}
|
||||
|
||||
public static function lastName()
|
||||
{
|
||||
return static::$lastName[array_rand(static::$lastName)];
|
||||
}
|
||||
|
||||
}
|
20
src/Provider/Base/PhoneNumber.php
Normal file
20
src/Provider/Base/PhoneNumber.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Provider\Base;
|
||||
|
||||
class PhoneNumber
|
||||
{
|
||||
protected static $formats = array('###-###-###');
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function phoneNumber()
|
||||
{
|
||||
return $this->generator->numerify(static::$formats[array_rand(static::$formats)]);
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Faker\Provider\en_US;
|
||||
|
||||
class Address
|
||||
require_once __DIR__ . '/../Base/Address.php';
|
||||
|
||||
class Address extends \Faker\Provider\Base\Address
|
||||
{
|
||||
protected static $cityPrefix = array('North', 'East', 'West', 'South', 'New', 'Lake', 'Port');
|
||||
protected static $citySuffix = array('town', 'ton', 'land', 'ville', 'berg', 'burgh', 'borough', 'bury', 'view', 'port', 'mouth', 'stad', 'furt', 'chester', 'mouth', 'fort', 'haven', 'side', 'shire');
|
||||
@ -65,81 +67,31 @@ class Address
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public static function cityPrefix()
|
||||
{
|
||||
return self::$cityPrefix[array_rand(self::$cityPrefix)];
|
||||
}
|
||||
|
||||
public static function citySuffix()
|
||||
{
|
||||
return self::$citySuffix[array_rand(self::$citySuffix)];
|
||||
}
|
||||
|
||||
public function buildingNumber()
|
||||
{
|
||||
$format = self::$buildingNumber[array_rand(self::$buildingNumber)];
|
||||
return $this->generator->numerify($format);
|
||||
}
|
||||
|
||||
public static function streetSuffix()
|
||||
{
|
||||
return self::$streetSuffix[array_rand(self::$streetSuffix)];
|
||||
}
|
||||
|
||||
public function city()
|
||||
{
|
||||
$format = self::$cityFormats[array_rand(self::$cityFormats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public function streetName()
|
||||
{
|
||||
$format = self::$streetNameFormats[array_rand(self::$streetNameFormats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public function streetAddress()
|
||||
{
|
||||
$format = self::$streetAddressFormats[array_rand(self::$streetAddressFormats)];
|
||||
return $this->generator->numerify($this->generator->parse($format));
|
||||
return static::$cityPrefix[array_rand(static::$cityPrefix)];
|
||||
}
|
||||
|
||||
public function secondaryAddress()
|
||||
{
|
||||
$format = self::$secondaryAddress[array_rand(self::$secondaryAddress)];
|
||||
$format = static::$secondaryAddress[array_rand(static::$secondaryAddress)];
|
||||
return $this->generator->numerify($format);
|
||||
}
|
||||
|
||||
public function postcode()
|
||||
{
|
||||
$format = self::$postcode[array_rand(self::$postcode)];
|
||||
$format = static::$postcode[array_rand(static::$postcode)];
|
||||
return $this->generator->numerify($format);
|
||||
}
|
||||
|
||||
public static function state()
|
||||
{
|
||||
return self::$state[array_rand(self::$state)];
|
||||
return static::$state[array_rand(static::$state)];
|
||||
}
|
||||
|
||||
public static function stateAbbr()
|
||||
{
|
||||
return self::$stateAbbr[array_rand(self::$stateAbbr)];
|
||||
}
|
||||
|
||||
public function address()
|
||||
{
|
||||
$format = self::$addressFormats[array_rand(self::$addressFormats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public static function country()
|
||||
{
|
||||
return self::$country[array_rand(self::$country)];
|
||||
return static::$stateAbbr[array_rand(static::$stateAbbr)];
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Faker\Provider\en_US;
|
||||
|
||||
class Company
|
||||
require_once __DIR__ . '/../Base/Company.php';
|
||||
|
||||
class Company extends \Faker\Provider\Base\Company
|
||||
{
|
||||
protected static $formats = array(
|
||||
'{{lastName}} {{companySuffix}}',
|
||||
@ -36,28 +38,10 @@ class Company
|
||||
|
||||
protected static $companySuffix = array('Inc','and Sons','LLC','Group','PLC','Ltd');
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
$format = self::$formats[array_rand(self::$formats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public function companySuffix()
|
||||
{
|
||||
return self::$companySuffix[array_rand(self::$companySuffix)];;
|
||||
}
|
||||
|
||||
public function catchPhrase()
|
||||
{
|
||||
$result = array();
|
||||
foreach (self::$catchPhraseWords as &$word) {
|
||||
foreach (static::$catchPhraseWords as &$word) {
|
||||
$result[] = $this->generator->randomElement($word);
|
||||
}
|
||||
|
||||
@ -67,7 +51,7 @@ class Company
|
||||
public function bs()
|
||||
{
|
||||
$result = array();
|
||||
foreach (self::$bsWords as &$word) {
|
||||
foreach (static::$bsWords as &$word) {
|
||||
$result[] = $this->generator->randomElement($word);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Faker\Provider\en_US;
|
||||
|
||||
class Name
|
||||
require_once __DIR__ . '/../Base/Name.php';
|
||||
|
||||
class Name extends \Faker\Provider\Base\Name
|
||||
{
|
||||
protected static $formats = array(
|
||||
'{{firstName}} {{lastName}}',
|
||||
@ -75,36 +77,13 @@ class Name
|
||||
|
||||
private static $suffix = array('Jr.','Sr.','I','II','III','IV','V','MD','DDS','PhD','DVM');
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function name()
|
||||
{
|
||||
$format = self::$formats[array_rand(self::$formats)];
|
||||
return $this->generator->parse($format);
|
||||
}
|
||||
|
||||
public static function firstName()
|
||||
{
|
||||
return self::$firstName[array_rand(self::$firstName)];
|
||||
}
|
||||
|
||||
public static function lastName()
|
||||
{
|
||||
return self::$lastName[array_rand(self::$lastName)];
|
||||
}
|
||||
|
||||
public static function prefix()
|
||||
{
|
||||
return self::$prefix[array_rand(self::$prefix)];
|
||||
return static::$prefix[array_rand(static::$prefix)];
|
||||
}
|
||||
|
||||
public static function suffix()
|
||||
{
|
||||
return self::$suffix[array_rand(self::$suffix)];
|
||||
return static::$suffix[array_rand(static::$suffix)];
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Faker\Provider\en_US;
|
||||
|
||||
class PhoneNumber
|
||||
require_once __DIR__ . '/../Base/PhoneNumber.php';
|
||||
|
||||
class PhoneNumber extends \Faker\Provider\Base\PhoneNumber
|
||||
{
|
||||
protected static $formats = array(
|
||||
'+##(#)##########',
|
||||
@ -30,16 +32,4 @@ class PhoneNumber
|
||||
'1-###-###-####x#####',
|
||||
'###.###.####x#####'
|
||||
);
|
||||
|
||||
protected $generator;
|
||||
|
||||
public function __construct($generator)
|
||||
{
|
||||
$this->generator = $generator;
|
||||
}
|
||||
|
||||
public function phoneNumber()
|
||||
{
|
||||
return $this->generator->numerify(self::$formats[array_rand(self::$formats)]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user