1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-22 08:19:52 +01:00

Canadian addresses and phone numbers

This commit is contained in:
Colin Viebrock 2013-03-12 10:52:02 -05:00
parent a1fd779b52
commit f43ce85625
2 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
namespace Faker\Provider\en_CA;
/**
* Extend US class since most fields share the same format
*/
class Address extends \Faker\Provider\en_US\Address
{
protected static $postcode = array('?#? #?#', '?#?-#?#', '?#?#?#');
protected static $postcodeLetters = array('A','B','C','E','G','H','J','K','L','M','N','P','R','S','T','V','X','Y');
protected static $province = array(
'Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland and Labrador', 'Northwest Territories' 'Nova Scotia', 'Nunavut', 'Ontario', 'Prince Edward Island', 'Quebec', 'Saskatchewan', 'Yukon Territory',
);
protected static $provinceAbbr = array(
'AB', 'BC', 'MB', 'NB', 'NL', 'NT', 'NS', 'NV', 'ON', 'PE', 'QC', 'SK', 'YT'
);
/**
* @example 'Ontario'
*/
public static function province()
{
return static::randomElement(static::$province);
}
/**
* @example 'ON'
*/
public static function provinceAbbr()
{
return static::randomElement(static::$provinceAbbr);
}
/**
* Returns a postalcodde-safe letter
* @example A1B 2C3
*/
public static function randomPostcodeLetter()
{
return static::randomElement(static::$postcodeLetters);
}
/**
* @example A1B 2C3
*/
public static function postcode()
{
$string = static::randomElement(static::$postcode);
$string = preg_replace_callback('/\#/', 'static::randomDigit', $string);
$string = preg_replace_callback('/\?/', 'static::randomPostcodeLetter', $string);
return static::toUpper($string);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Faker\Provider\en_CA;
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
protected static $formats = array(
'%##-###-####',
'%##.###.####',
'%## ### ####',
'(%##) ###-####',
'1-%##-###-####',
'1 (%##) ###-####',
'+1 (%##) ###-####',
'%##-###-#### x###',
'%##.###.#### x###',
'%## ### #### x###',
'(%##) ###-#### x###',
'1-%##-###-#### x###',
'1 (%##) ###-#### x###',
'+1 (%##) ###-#### x###',
);
}