From a19c7ed305f03c2d6d53a37c4e8237c0cd3220b4 Mon Sep 17 00:00:00 2001 From: Joshua Gigg Date: Sat, 21 Dec 2013 17:18:16 +0000 Subject: [PATCH] Update README Also use fully qualified namespace for \Exception --- README.md | 52 +++++++++++++++++++++++++- src/libphonenumber/ShortNumberInfo.php | 2 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 04f30faa4..b5d408ea7 100644 --- a/README.md +++ b/README.md @@ -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" } } ``` @@ -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 @@ -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 @@ -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. \ No newline at end of file diff --git a/src/libphonenumber/ShortNumberInfo.php b/src/libphonenumber/ShortNumberInfo.php index 6137ec717..77f507341 100644 --- a/src/libphonenumber/ShortNumberInfo.php +++ b/src/libphonenumber/ShortNumberInfo.php @@ -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();