/** * Extracts the pattern for international format. If there is no intlFormat, default to using the * national format. If the intlFormat is set to "NA" the intlFormat should be ignored. * * @throws RuntimeException if multiple intlFormats have been encountered. * @return whether an international number format is defined. */ private static function loadInternationalFormat(PhoneMetadata $metadata, \DOMElement $numberFormatElement, $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()); } 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; } } if ($intlFormat->hasFormat()) { $metadata->addIntlNumberFormat($intlFormat); } return $hasExplicitIntlFormatDefined; }