Skip to content

Commit

Permalink
Merge pull request #26 from giggsey/61
Browse files Browse the repository at this point in the history
Google v6.1 changes
  • Loading branch information
giggsey committed May 19, 2014
2 parents bd6bd81 + f7224d4 commit 6b30738
Show file tree
Hide file tree
Showing 79 changed files with 39,158 additions and 27,931 deletions.
6 changes: 4 additions & 2 deletions Tests/libphonenumber/Tests/core/PhoneNumberUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use libphonenumber\CountryCodeSource;
use libphonenumber\CountryCodeToRegionCodeMapForTesting;
use libphonenumber\DefaultMetadataLoader;
use libphonenumber\MatchType;
use libphonenumber\NumberFormat;
use libphonenumber\NumberParseException;
Expand Down Expand Up @@ -158,7 +159,7 @@ public function testMissingMetadataFileThrowsRuntimeException()
// do is make sure the exception has the file name in it.

try {
$this->phoneUtil->loadMetadataFromFile("no/such/file", "XX", -1);
$this->phoneUtil->loadMetadataFromFile("no/such/file", "XX", -1, new DefaultMetadataLoader());
$this->fail("Expected Exception");
} catch (\RuntimeException $e) {
$this->assertContains('no/such/file_XX', $e->getMessage(), "Unexpected error: " . $e->getMessage());
Expand All @@ -168,7 +169,8 @@ public function testMissingMetadataFileThrowsRuntimeException()
$this->phoneUtil->loadMetadataFromFile(
"no/such/file",
PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY,
123
123,
new DefaultMetadataLoader()
);
$this->fail("Expected Exception");
} catch (\RuntimeException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
array (
0 => '11',
),
'nationalPrefixFormattingRule' => '0$1',
'domesticCarrierCodeFormattingRule' => '',
),
1 =>
array (
Expand All @@ -170,6 +172,8 @@
array (
0 => '1[02-9]|[23]',
),
'nationalPrefixFormattingRule' => '0$1',
'domesticCarrierCodeFormattingRule' => '',
),
2 =>
array (
Expand Down Expand Up @@ -197,6 +201,8 @@
array (
0 => '[68]',
),
'nationalPrefixFormattingRule' => '0$1',
'domesticCarrierCodeFormattingRule' => '',
),
),
'mainCountryForCode' => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* This file is automatically @generated by {@link BuildMetadataPHPFromXml}.
* Please don't modify it directly.
*/


return array (
'generalDesc' =>
array (
),
'fixedLine' =>
array (
),
'mobile' =>
array (
),
'tollFree' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'premiumRate' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'sharedCost' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'personalNumber' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'voip' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'pager' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'uan' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'emergency' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'voicemail' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'shortCode' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'standardRate' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'carrierSpecific' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'noInternationalDialling' =>
array (
'NationalNumberPattern' => 'NA',
'PossibleNumberPattern' => 'NA',
),
'id' => 'CN',
'countryCode' => 86,
'internationalPrefix' => '',
'sameMobileAndFixedLinePattern' => true,
'numberFormat' =>
array (
0 =>
array (
'pattern' => '(\\d{3})(\\d{5,6})',
'format' => '$1 $2',
'leadingDigitsPatterns' =>
array (
0 => '[3-9]',
1 => '[3-9]\\d{2}[19]',
2 => '
[3-9]\\d{2}(?:
10|
95
)
',
),
'nationalPrefixFormattingRule' => '$1',
'domesticCarrierCodeFormattingRule' => '$CC $1',
),
),
'intlNumberFormat' =>
array (
),
'mainCountryForCode' => false,
'leadingZeroPossible' => false,
'mobileNumberPortableRegion' => false,
);
/* EOF */
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
array (
0 => '[89]00',
),
'nationalPrefixFormattingRule' => '01 $1',
'domesticCarrierCodeFormattingRule' => '',
),
1 =>
array (
Expand All @@ -170,6 +172,8 @@
array (
0 => '33|55|81',
),
'nationalPrefixFormattingRule' => '01 $1',
'domesticCarrierCodeFormattingRule' => '',
),
2 =>
array (
Expand All @@ -179,6 +183,8 @@
array (
0 => '[2467]|3[0-24-9]|5[0-46-9]|8[2-9]|9[1-9]',
),
'nationalPrefixFormattingRule' => '01 $1',
'domesticCarrierCodeFormattingRule' => '',
),
3 =>
array (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
'leadingDigitsPatterns' =>
array (
),
'nationalPrefixFormattingRule' => '',
'domesticCarrierCodeFormattingRule' => '',
),
),
'mainCountryForCode' => true,
Expand Down
32 changes: 14 additions & 18 deletions build/libphonenumber/buildtools/BuildMetadataFromXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ private static function loadAvailableFormats(
} else {
$format->setDomesticCarrierCodeFormattingRule($carrierCodeFormattingRule);
}
$nationalFormat = self::loadNationalFormat($metadata, $numberFormatElement, $format);
self::loadNationalFormat($metadata, $numberFormatElement, $format);
$metadata->addNumberFormat($format);

if (self::loadInternationalFormat($metadata, $numberFormatElement, $nationalFormat)) {
if (self::loadInternationalFormat($metadata, $numberFormatElement, $format)) {
$hasExplicitIntlFormatDefined = true;
}
}
Expand Down Expand Up @@ -261,7 +261,6 @@ private static function getDomesticCarrierCodeFormattingRuleFromElement(\DOMElem
* @param \DOMElement $numberFormatElement
* @param NumberFormat $format
* @throws \RuntimeException if multiple or no formats have been encountered.
* @return string the national format string.
*/
private static function loadNationalFormat(
PhoneMetadata $metadata,
Expand All @@ -277,7 +276,6 @@ private static function loadNationalFormat(
}
$nationalFormat = $formatPattern->item(0)->firstChild->nodeValue;
$format->setFormat($nationalFormat);
return $nationalFormat;
}

public static function setLeadingDigitsPatterns(\DOMElement $numberFormatElement, NumberFormat $format)
Expand All @@ -301,34 +299,32 @@ public static function setLeadingDigitsPatterns(\DOMElement $numberFormatElement
*
* @param PhoneMetadata $metadata
* @param \DOMElement $numberFormatElement
* @param string $nationalFormat
* @param NumberFormat $nationalFormat
* @throws \RuntimeException if multiple intlFormats have been encountered.
* @return bool whether an international number format is defined.
*/
private static function loadInternationalFormat(
PhoneMetadata $metadata,
\DOMElement $numberFormatElement,
$nationalFormat
NumberFormat $nationalFormat
) {
$intlFormat = new NumberFormat();
self::setLeadingDigitsPatterns($numberFormatElement, $intlFormat);
$intlFormat->setPattern($numberFormatElement->getAttribute(self::PATTERN));
$intlFormatPattern = $numberFormatElement->getElementsByTagName(self::INTL_FORMAT);
$hasExplicitIntlFormatDefined = false;

if ($intlFormatPattern->length > 1) {
throw new \RuntimeException("Invalid number of intlFormat patterns for country: " . $metadata->getId());
} elseif ($intlFormatPattern->length == 0) {
// Default to use the same as the national pattern if none is defined.
$intlFormat->mergeFrom($nationalFormat);
} else {
if ($intlFormatPattern->length == 0) {
// Default to use the same as the national pattern if none is defined.
$intlFormat->setFormat($nationalFormat);
} else {
$intlFormatPatternValue = $intlFormatPattern->item(0)->firstChild->nodeValue;
if ($intlFormatPatternValue !== "NA") {
$intlFormat->setFormat($intlFormatPatternValue);
}
$hasExplicitIntlFormatDefined = true;
$intlFormat->setPattern($numberFormatElement->getAttribute(self::PATTERN));
self::setLeadingDigitsPatterns($numberFormatElement, $intlFormat);
$intlFormatPatternValue = $intlFormatPattern->item(0)->firstChild->nodeValue;
if ($intlFormatPatternValue !== "NA") {
$intlFormat->setFormat($intlFormatPatternValue);
}
$hasExplicitIntlFormatDefined = true;
}

if ($intlFormat->hasFormat()) {
Expand Down Expand Up @@ -464,4 +460,4 @@ public static function buildCountryCodeToRegionCodeMap($metadataCollection)

}

/* EOF */
/* EOF */
4 changes: 4 additions & 0 deletions src/libphonenumber/CountryCodeToRegionCodeMapForTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class CountryCodeToRegionCodeMapForTesting {
array (
0 => 'KR',
),
86 =>
array (
0 => 'CN',
),
244 =>
array (
0 => 'AO',
Expand Down
14 changes: 14 additions & 0 deletions src/libphonenumber/DefaultMetadataLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace libphonenumber;


class DefaultMetadataLoader implements MetadataLoader
{
public function loadMetadata($metadataFileName)
{
return include $metadataFileName;
}
}

/* EOF */
15 changes: 15 additions & 0 deletions src/libphonenumber/MetadataLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace libphonenumber;


interface MetadataLoader
{
/**
* @param string $metadataFileName File name (including path) of metadata to load.
* @return mixed
*/
public function loadMetadata($metadataFileName);
}

/* EOF */
2 changes: 1 addition & 1 deletion src/libphonenumber/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function clear()
return $this;
}

public function mergeFrom(PhoneNumber $other)
public function mergeFrom(PhoneNumber $other)
{
if ($other->hasCountryCode()) {
$this->setCountryCode($other->getCountryCode());
Expand Down
Loading

0 comments on commit 6b30738

Please sign in to comment.