Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #283 from JasonMortonNZ/master
Browse files Browse the repository at this point in the history
NEW - Added NZ localisation
  • Loading branch information
fzaninotto committed Jul 10, 2014
2 parents e46ce3e + 05fdbb9 commit 01b708e
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 0 deletions.
15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,21 @@ echo $faker->tollFreePhoneNumber; // "0800123456"
echo $faker->premiumRatePhoneNumber; // "0900123456"
```

### `Faker\Provider\en_NZ\Phone`

```php
<?php

// Generates a cell (mobile) phone number
echo $faker->cellNumber; // "021 123 4567"

// Generates a toll free number
echo $faker->tollFreeNumber; // "0800 123 456"

// Area Code
echo $faker->areaCode; // "03"
```

## License

Faker is released under the MIT Licence. See the bundled LICENSE file for details.
84 changes: 84 additions & 0 deletions src/Faker/Provider/en_NZ/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Faker\Provider\en_NZ;

class Address extends \Faker\Provider\Address
{

/**
* An array of en_NZ (New Zealand) building number formats
* @var array
*/
protected static $buildingNumber = array('#', '##', '###');

/**
* An array of en_NZ (New Zealand) street suffixes
* @var array
*/
protected static $streetSuffix = array(
'Avenue', 'Close', 'Court', 'Crescent', 'Drive', 'Esplanade', 'Grove', 'Heights', 'Highway', 'Hill', 'Lane', 'Line', 'Mall', 'Parade', 'Place', 'Quay', 'Rise', 'Road', 'Square', 'Street', 'Terrace', 'Way'
);

/**
* City suffixes
* @var array
*/
protected static $citySuffix = array('ville', 'ston');

/**
* City formats
* @var array
*/
protected static $cityFormats = array('{{firstName}}{{citySuffix}}');

/**
* An array of en_NZ (New Zealand) regions
* @see http://en.wikipedia.org/wiki/Regions_of_New_Zealand
* @var array
*/
protected static $region = array(
'Auckland', 'Bay of Plenty', 'Canterbury', 'Gisborne', 'Hawkes Bay', 'Manawatu-Whanganui', 'Marlborough', 'Nelson', 'Northland', 'Otago', 'Southland', 'Taranaki', 'Tasman', 'Waikato', 'Wellington', 'West Coast'
);

/**
* An array of en_NZ (New Zealand) poscode formats
* @var array
*/
protected static $postcode = array('####');

/**
* An array of en_NZ (New Zealand) countries
* @var array
*/
protected static $country = array('New Zealand');

/**
* An array of en_NZ (New Zealand) address formats
* @var array
*/
protected static $addressFormats = array('{{buildingNumber}} {{streetName}}, {{city}}, {{region}}, {{postcode}}');

/**
* An array of en_NZ (New Zealand) street address formats
* @var array
*/
protected static $streetAddressFormats = array('{{buildingNumber}} {{streetName}}');

/**
* Return a en_NZ (New Zealand) postcode
* @return string
*/
public static function postcode()
{
return static::numerify(static::randomElement(static::$postcode));
}

/**
* Return a en_NZ (New Zealand) region
* @return string
*/
public static function region()
{
return static::randomElement(static::$region);
}
}
14 changes: 14 additions & 0 deletions src/Faker/Provider/en_NZ/Internet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Faker\Provider\en_NZ;

class Internet extends \Faker\Provider\Internet
{
/**
* An array of common en_NZ (New Zeland) TLD's
* @var array
*/
protected static $tld = array(
'com', 'co.nz', 'ac.nz', 'geek.nz', 'gen.nz', 'kiwi.nz', 'maori.nz', 'net.nz', 'org.nz', 'school.nz', 'govt.nz', 'iwi.nz', 'mil.nz', 'health.nz', 'parliment.nz'
);
}
115 changes: 115 additions & 0 deletions src/Faker/Provider/en_NZ/PhoneNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Faker\Provider\en_NZ;

class PhoneNumber extends \Faker\Provider\PhoneNumber
{
/**
* An array of en_NZ landline phone number formats
* @var array
*/
protected static $formats = array(
// National Calls
'{{area_code}}{{beginning_number}}######',
'{{area_code}} {{beginning_number}}## ####'
);

/**
* An array of en_NZ mobile (cell) phone number formats
* @var array
*/
protected static $mobileFormats = array(
// Local
'02########',
'02#########',
'02# ### ####',
'02# #### ####'
);

/**
* An array of toll free phone number formats
* @var array
*/
protected static $tollFreeFormats = array(
'0508######',
'0508 ######',
'0508 ### ###',
'0800######',
'0800 ######',
'0800 ### ###',
);

/**
* An array of en_NZ landline area codes
* @var array
*/
protected static $areaCodes = array(
'02', '03', '04', '06', '07', '09'
);

/**
* An array of en_NZ landline beginning numbers
* @var array
*/
protected static $beginningNumbers = array(
'2', '3', '4', '5', '6', '7', '8', '9'
);

/**
* Return a en_NZ landline phone number
* @return string
*/
public static function phoneNumber()
{
$format = static::numerify(static::randomElement(static::$formats));

$withAreaCode = str_replace('{{area_code}}', static::areaCode(), $format);

return str_replace('{{beginning_number}}', static::beginningNumber(), $withAreaCode);
}

/**
* Return a en_NZ mobile phone number
* @return string
*/
public static function mobileNumber()
{
return static::numerify(static::randomElement(static::$mobileFormats));
}

/**
* Return a en_NZ cell (mobile) phone number
* @return string
*/
public static function cellNumber()
{
return static::mobileNumber();
}

/**
* Return a en_NZ toll free phone number
* @return string
*/
public static function tollFreeNumber()
{
return static::numerify(static::randomElement(static::$tollFreeFormats));
}

/**
* Return a en_NZ landline area code
* @return string
*/
public static function areaCode()
{
return static::numerify(static::randomElement(static::$areaCodes));
}

/**
* Return a en_NZ landline beginning number
* @return string
*/
public static function beginningNumber()
{
return static::numerify(static::randomElement(static::$beginningNumbers));
}
}

0 comments on commit 01b708e

Please sign in to comment.