libphonenumber\NumberFormat::mergeFrom PHP Method

mergeFrom() public method

public mergeFrom ( NumberFormat $other ) : NumberFormat
$other NumberFormat
return NumberFormat
    public function mergeFrom(NumberFormat $other)
    {
        if ($other->hasPattern()) {
            $this->setPattern($other->getPattern());
        }
        if ($other->hasFormat()) {
            $this->setFormat($other->getFormat());
        }
        $leadingDigitsPatternSize = $other->leadingDigitsPatternSize();
        for ($i = 0; $i < $leadingDigitsPatternSize; $i++) {
            $this->addLeadingDigitsPattern($other->getLeadingDigitsPattern($i));
        }
        if ($other->hasNationalPrefixFormattingRule()) {
            $this->setNationalPrefixFormattingRule($other->getNationalPrefixFormattingRule());
        }
        if ($other->hasDomesticCarrierCodeFormattingRule()) {
            $this->setDomesticCarrierCodeFormattingRule($other->getDomesticCarrierCodeFormattingRule());
        }
        $this->setNationalPrefixOptionalWhenFormatting($other->isNationalPrefixOptionalWhenFormatting());
        return $this;
    }

Usage Example

 /**
  * 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.
  *
  * @param PhoneMetadata $metadata
  * @param \DOMElement $numberFormatElement
  * @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, NumberFormat $nationalFormat)
 {
     $intlFormat = new NumberFormat();
     $intlFormatPattern = $numberFormatElement->getElementsByTagName(self::INTL_FORMAT);
     $hasExplicitIntlFormatDefined = false;
     if ($intlFormatPattern->length > 1) {
         $countryId = strlen($metadata->getId()) > 0 ? $metadata->getId() : $metadata->getCountryCode();
         throw new \RuntimeException("Invalid number of intlFormat patterns for country: " . $countryId);
     } elseif ($intlFormatPattern->length == 0) {
         // Default to use the same as the national pattern if none is defined.
         $intlFormat->mergeFrom($nationalFormat);
     } else {
         $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()) {
         $metadata->addIntlNumberFormat($intlFormat);
     }
     return $hasExplicitIntlFormatDefined;
 }
All Usage Examples Of libphonenumber\NumberFormat::mergeFrom