Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
Also use fully qualified namespace for \Exception
  • Loading branch information
giggsey committed Dec 21, 2013
1 parent 1dd32a1 commit a19c7ed
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The PECL [intl](http://php.net/intl) extension is required for this library to b
```json
{
"require": {
"giggsey/libphonenumber-for-php": "~5.8"
"giggsey/libphonenumber-for-php": "~5.9"
}
}
```
Expand Down Expand Up @@ -79,6 +79,20 @@ There are a few formats supported by the formatting method, as illustrated below
```php
// Produces "+41446681800"
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::E164) . PHP_EOL;
// Produces "044 668 18 00"
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::NATIONAL) . PHP_EOL;
// Produces "+41 44 668 18 00"
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::INTERNATIONAL) . PHP_EOL;
```

You could also choose to format the number in the way it is dialled from another country:

```php
// Produces "011 41 44 668 1800", the number when it is dialled in the United States.
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "US");

// Produces "00 41 44 668 18 00", the number when it is dialled in Great Britain.
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "GB");
```

### Geocoder
Expand Down Expand Up @@ -113,6 +127,29 @@ echo $geocoder->getDescriptionForNumber($gbNumberProto, "en_GB") . PHP_EOL;
echo $geocoder->getDescriptionForNumber($gbNumberProto, "ko-KR") . PHP_EOL;
```

### ShortNumberInfo

```php
$shortNumberInfo = \libphonenumber\ShortNumberInfo::getInstance();

// true
var_dump($shortNumberInfo->isEmergencyNumber("999", "GB"));
// true
var_dump($shortNumberInfo->connectsToEmergencyNumber("999", "GB"));
// false
var_dump($shortNumberInfo->connectsToEmergencyNumber("911", "GB"));

// true
var_dump($shortNumberInfo->isEmergencyNumber("911", "US"));
// true
var_dump($shortNumberInfo->connectsToEmergencyNumber("911", "US"));

// false
var_dump($shortNumberInfo->isEmergencyNumber("911123", "US"));
// true
var_dump($shortNumberInfo->connectsToEmergencyNumber("911123", "US"));
```

### Mapping Phone Numbers to carrier

```php
Expand All @@ -125,6 +162,19 @@ $carrierMapper = \libphonenumber\PhoneNumberToCarrierMapper::getInstance();
echo $carrierMapper->getDescriptionForNumber($swissNumberProto, "en");
```

### Mapping Phone Numbers to TimeZones

```php

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$swissNumberProto = $phoneUtil->parse("798765432", "CH");

$timeZoneMapper = \libphonenumber\PhoneNumberToTimeZonesMapper::getInstance();
// returns array("Europe/Zurich")
$timeZones = $timeZoneMapper->getTimeZonesForNumber($swissNumberProto);

```

## Generating data

Data can be generated using phing, running the 'compile' target.
2 changes: 1 addition & 1 deletion src/libphonenumber/ShortNumberInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function loadMetadataFromFile($filePrefix, $regionCode, $countryCallingC
$isNonGeoRegion = PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY === $regionCode;
$fileName = $filePrefix . '_' . ($isNonGeoRegion ? $countryCallingCode : $regionCode) . '.php';
if (!is_readable($fileName)) {
throw new Exception('missing metadata: ' . $fileName);
throw new \Exception('missing metadata: ' . $fileName);
} else {
$data = include $fileName;
$metadata = new PhoneMetadata();
Expand Down

0 comments on commit a19c7ed

Please sign in to comment.