update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -0,0 +1,54 @@
# PhoneNumberOfflineGeocoder
The Phone Number Geocoder requires the PHP [intl](http://php.net/intl) extension.
## Getting Started
As with [PhoneNumberUtil](PhoneNumberUtil.md), the Phone Number Geocoder uses a singleton.
```php
$geoCoder = \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance();
```
## `getDescriptionForNumber()`
Returns a text description for the supplied `PhoneNumber` object, in the `$locale` language supplied.
The description returned might consist of the name of the country, or the name of the geographical area the phone number is from.
If `$userRegion` is supplied, it will also be taken into consideration. If the phone number is from the same region, only a lower-level description will be returned.
```php
$gbNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse('0161 496 0123', 'GB');
var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'en'));
// string(10) "Manchester"
var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'en_GB', 'GB'));
// string(10) "Manchester"
var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'en_GB', 'US'));
// string(14) "United Kingdom"
var_dump($geoCoder->getDescriptionForNumber($gbNumber, 'ko-KR', 'US'));
// string(6) "영국" (Korean for United Kingdom)
$usNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse("+1 650 253 0000", "US");
var_dump($geoCoder->getDescriptionForNumber($usNumber, 'en'));
// string(10) "Mountain View, CA"
var_dump($geoCoder->getDescriptionForNumber($usNumber, 'en_GB', 'GB'));
// string(10) "United States"
var_dump($geoCoder->getDescriptionForNumber($usNumber, 'en_GB', 'US'));
// string(14) "Mountain View, CA"
var_dump($geoCoder->getDescriptionForNumber($usNumber, 'ko-KR', 'US'));
// string(6) "영국" (Korean for United States)
```
## `getDescriptionForValidNumber()`
Returns the same as `getDescriptionForNumber()`, but assumes that you have already checked whether the number is suitable for geolocation.

View File

@@ -0,0 +1,30 @@
# PhoneNumberToCarrierMapper
The Phone Number Carrier Mapper requires the PHP [intl](http://php.net/intl) extension.
## Getting Started
As with [PhoneNumberUtil](PhoneNumberUtil.md), the Phone Number Carrier Mapper uses a singleton.
```php
$carrierMapper = \libphonenumber\PhoneNumberToCarrierMapper::getInstance();
```
## `getNameForNumber()`
Returns the name of the carrier for the supplied `PhoneNumber` object within the `$language` supplied.
```php
$chNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse("798765432", "CH");
var_dump($carrierMapper->getNameForNumber($chNumber, 'en'));
// string(8) "Swisscom"
```
## `getNameForValidNumber()`
Returns the same as `getNameForNumber()` without checking whether it is a valid number for carrier mapping.
## `getSafeDisplayName()`
Returns the same as `getNameForNumber()`, but only if the number is safe for carrier mapping. A number is only validate for carrier mapping if it's a Mobile or Fixed line, and the country does not support Mobile Number Portability.

View File

@@ -0,0 +1,30 @@
# PhoneNumberToTimeZonesMapper
## Getting Started
As with [PhoneNumberUtil](PhoneNumberUtil.md), the Phone Number Timezone Mapper uses a singleton.
```php
$timezoneMapper = \libphonenumber\PhoneNumberToTimeZonesMapper::getInstance();
```
## `getTimeZonesForNumber()`
Returns an array of timezones for which the `PhoneNumber` object supplied belongs in.
```php
$usNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse("+1 650 253 0000", "US");
var_dump($timezoneMapper->getTimeZonesForNumber($usNumber));
// array(1) { [0]=> string(19) "America/Los_Angeles" }
/*
* A US Toll Free number is not geographically tied to any location, so could be in any US timezone
*/
$usNumber = \libphonenumber\PhoneNumberUtil::getInstance()->parse("+1 800 253 0000", "US");
var_dump($timezoneMapper->getTimeZonesForNumber($usNumber));
// array(35) { [0]=> string(16) "America/Anguilla" [1]=> string(15) "America/Antigua" [2]=> string(16) "America/Barbados" [3]=> string(14) "America/Cayman" [4]=> string(15) "America/Chicago" [5]=> string(14) "America/Denver" [6]=> string(16) "America/Dominica" [7]=> string(16) "America/Edmonton" [8]=> string(18) "America/Grand_Turk" [9]=> string(15) "America/Grenada" [10]=> string(15) "America/Halifax" [11]=> string(15) "America/Jamaica" [12]=> string(14) "America/Juneau" [13]=> string(19) "America/Los_Angeles" [14]=> string(21) "America/Lower_Princes" [15]=> string(18) "America/Montserrat" [16]=> string(14) "America/Nassau" [17]=> string(16) "America/New_York" [18]=> string(21) "America/Port_of_Spain" [19]=> string(19) "America/Puerto_Rico" [20]=> string(21) "America/Santo_Domingo" [21]=> string(16) "America/St_Johns" [22]=> string(16) "America/St_Kitts" [23]=> string(16) "America/St_Lucia" [24]=> string(17) "America/St_Thomas" [25]=> string(18) "America/St_Vincent" [26]=> string(15) "America/Toronto" [27]=> string(15) "America/Tortola" [28]=> string(17) "America/Vancouver" [29]=> string(16) "America/Winnipeg" [30]=> string(16) "Atlantic/Bermuda" [31]=> string(12) "Pacific/Guam" [32]=> string(16) "Pacific/Honolulu" [33]=> string(17) "Pacific/Pago_Pago" [34]=> string(14) "Pacific/Saipan" }
```

View File

@@ -6,7 +6,7 @@
Returns a `PhoneNumber` object version of the `$number` supplied with the `$region` code.
If the number is passed in an international format (e.g. `+44 117 496 123`), then the region code is not needed, and can be `null`. Failing that, the library will use the region code to work out the phone number based on rules loaded for that region.
If the number is passed in an international format (e.g. `+44 117 496 0123`), then the region code is not needed, and can be `null`. Failing that, the library will use the region code to work out the phone number based on rules loaded for that region.
```php
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
@@ -42,7 +42,7 @@ object(libphonenumber\PhoneNumber)#31 (9) {
}
```
A `PhoneNumberException` will be thrown if it is unable to obtain a viable number. For example, if the number is too short/long, or the region is invalid. This does not tell you whether the number is valid or not. In order to determine whether the number is valid, it needs to be checked in the validation functions.
A `NumberParseException` will be thrown if it is unable to obtain a viable number. For example, if the number is too short/long, or the region is invalid. This does not tell you whether the number is valid or not. In order to determine whether the number is valid, it needs to be checked in the validation functions.
The returned `PhoneNumber` object is used with other functions to provide additional information.
@@ -196,8 +196,27 @@ var_dump($phoneNumberUtil->getExampleNumber('GB'));
Returns an example `PhoneNumber` object for the `$regionCode` supplied of the `PhoneNumberType`.
This also accepts the first parameter being a `PhoneNumberType`, where it will return a valid number
for the specified number type from any country. Just leave the second parameter as null.
```php
var_dump($phoneNumberUtil->getExampleNumberForType('GB', PhoneNumberType::MOBILE));
// (PhoneNumber) Country Code: 44 National Number: 7400123456 ...
var_dump($phoneNumberUtil->getExampleNumberForType(PhoneNumberType::MOBILE));
// (PhoneNumber) Country Code: 1 National Number: 2015555555 ...
```
### `getInvalidExampleNumber()`
Returns an example invalid `PhoneNumber` object for the `$regionCode` supplied.
This can be useful for unit testing, where you want to test with an invalid number.
The number returned will be able to be parsed. It may also be a valid short number
for the region.
```php
var_dump($phoneNumberUtil->getInvalidExampleNumber('GB'));
// (PhoneNumber) Country Code: 44 National Number: 121234567 ...
```

View File

@@ -0,0 +1,172 @@
# ShortNumberInfo
## Getting Started
As with [PhoneNumberUtil](PhoneNumberUtil.md), ShortNumberInfo uses a singleton.
```php
$shortNumberUtil = \libphonenumber\ShortNumberInfo::getInstance();
```
## Example Numbers
### `getExampleShortNumber()`
Returns an example short phone number for the `$regionCode` supplied
```php
var_dump($shortNumberUtil->getExampleShortNumber('GB'));
// string(3) "150"
```
### `getExampleShortNumberForCost()`
Returns a valid short number for the specified `$regionCode` and `$cost` category.
```php
var_dump($shortNumberUtil->getExampleShortNumberForCost('GB', \libphonenumber\ShortNumberCost::TOLL_FREE));
// string(6) "116000"
var_dump($shortNumberUtil->getExampleShortNumberForCost('GB', \libphonenumber\ShortNumberCost::PREMIUM_RATE));
// string(0) ""
var_dump($shortNumberUtil->getExampleShortNumberForCost('US', \libphonenumber\ShortNumberCost::PREMIUM_RATE));
// string(5) "24280"
```
## Emergency Numbers
### `isEmergencyNumber()`
Returns whether the supplied `$number` exactly matches an emergency service number for the `$region`.
```php
var_dump($shortNumberUtil->isEmergencyNumber('999', 'GB'));
// bool(true)
var_dump($shortNumberUtil->isEmergencyNumber('9999', 'GB'));
// bool(false)
```
### `connectsToEmergencyNumber()`
Checks whether the `$number` (when dialled) might connect to an emergency service within the given `$region`.
```php
var_dump($shortNumberUtil->connectsToEmergencyNumber('999', 'GB'));
// bool(true)
// Note, 999 is a GB emergency service, but additional digits after the 999
// might be possible to dial.
var_dump($shortNumberUtil->connectsToEmergencyNumber('999123', 'GB'));
// bool(true)
```
## Short Number Validation
### `isPossibleShortNumber()`
Checks whether the specified `PhoneNumber` object is a possible short number.
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(44);
$phoneNumber->setNationalNumber(118118);
var_dump($shortNumberUtil->isPossibleShortNumber($phoneNumber));
// bool(true)
```
### `isPossibleShortNumberForRegion()`
Checks whether the supplied `$shortNumber` (which can either be a string or a `PhoneNumber` object) is possible for the `$region`.
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(44);
$phoneNumber->setNationalNumber(118118);
var_dump($shortNumberUtil->isPossibleShortNumberForRegion($phoneNumber, 'GB'));
// bool(true)
var_dump($shortNumberUtil->isPossibleShortNumberForRegion('1234', 'GB'));
// bool(true)
```
### `isValidShortNumber()`
Checks whether the specified `PhoneNumber` object is a valid short number.
**Important:** This doesn't actually validate whether the number is in use. libphonenumber-for-php is only able to validate number patterns, and isn't able to check with telecommunication providers.
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(44);
$phoneNumber->setNationalNumber(118118);
var_dump($shortNumberUtil->isValidShortNumber($phoneNumber));
// bool(true)
```
### `isValidShortNumberForRegion()`
Checks whether the supplied `$shortNumber` (which can either be a string or a `PhoneNumber` object) is valid for the `$region`.
**Important:** As with `isValidShortNumber()`, this can not validate whether the number is actually in use.
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(44);
$phoneNumber->setNationalNumber(118118);
var_dump($shortNumberUtil->isValidShortNumberForRegion($phoneNumber, 'GB'));
// bool(true)
var_dump($shortNumberUtil->isValidShortNumberForRegion('1234', 'GB'));
// bool(false)
```
### `isCarrierSpecific()`
Returns whether the supplied `PhoneNumber` is a carrier specific short number.
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(1);
$phoneNumber->setNationalNumber(611);
var_dump($shortNumberUtil->isCarrierSpecific($phoneNumber));
// (bool) true
```
## Expected Costs
### `getExpectedCost()`
Returns the expected cost (as a `ShortNumberCost` constant) of the supplied `PhoneNumber` short number.
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(44);
$phoneNumber->setNationalNumber(118118);
var_dump($shortNumberUtil->getExpectedCost($phoneNumber, 'GB'));
// int(10) (ShortNumberCost::UNKNOWN_COST)
```
### `getExpectedCostForRegion()`
Returns the expected cost (as a `ShortNumberCost` constant) of the supplied `$number` (which can be a string or a `PhoneNumber` object).
```php
$phoneNumber = new \libphonenumber\PhoneNumber();
$phoneNumber->setCountryCode(44);
$phoneNumber->setNationalNumber(118118);
var_dump($shortNumberUtil->getExpectedCostForRegion($phoneNumber, 'GB'));
// int(10) (ShortNumberCost::UNKNOWN_COST)
var_dump($shortNumberUtil->getExpectedCostForRegion('24280', 'US'));
// int(4) (ShortNumberCost::PREMIUM_RATE)
```