setItalianLeadingZero() public method

Sets whether this phone number uses an italian leading zero.
public setItalianLeadingZero ( boolean $value ) : PhoneNumber
$value boolean True to use italian leading zero, false otherwise.
return PhoneNumber This PhoneNumber instance, for chaining method calls.
Esempio n. 1
0
 public function testSerializingPhoneNumber2()
 {
     $phoneNumber = new PhoneNumber();
     $phoneNumber->setCountryCode(1);
     $phoneNumber->setNationalNumber(1);
     $phoneNumber->setExtension(1);
     $phoneNumber->setItalianLeadingZero(1);
     $phoneNumber->setNumberOfLeadingZeros(1);
     $phoneNumber->setRawInput(1);
     $phoneNumber->setCountryCodeSource(1);
     $phoneNumber->setPreferredDomesticCarrierCode(1);
     $serializedString = serialize($phoneNumber);
     $phoneObject2 = unserialize($serializedString);
     $this->assertTrue($phoneObject2->equals($phoneNumber));
 }
 /**
  * A helper function to set the values related to leading zeros in a PhoneNumber.
  * @param $nationalNumber
  * @param PhoneNumber $phoneNumber
  */
 public static function setItalianLeadingZerosForPhoneNumber($nationalNumber, PhoneNumber $phoneNumber)
 {
     if (strlen($nationalNumber) > 1 && substr($nationalNumber, 0, 1) == '0') {
         $phoneNumber->setItalianLeadingZero(true);
         $numberOfLeadingZeros = 1;
         // Note that if the national number is all "0"s, the last "0" is not counted as a leading
         // zero.
         while ($numberOfLeadingZeros < strlen($nationalNumber) - 1 && substr($nationalNumber, $numberOfLeadingZeros, 1) == '0') {
             $numberOfLeadingZeros++;
         }
         if ($numberOfLeadingZeros != 1) {
             $phoneNumber->setNumberOfLeadingZeros($numberOfLeadingZeros);
         }
     }
 }
 /**
  * Returns a text description for the given phone number, in the language provided. The
  * description might consist of the name of the country where the phone number is from, or the
  * name of the geographical area the phone number is from if more detailed information is
  * available.
  *
  * <p>This method assumes the validity of the number passed in has already been checked, and that
  * the number is suitable for geocoding. We consider fixed-line and mobile numbers possible
  * candidates for geocoding.
  *
  * <p>If $userRegion is set, we also consider the region of the user. If the phone number is from
  * the same region as the user, only a lower-level description will be returned, if one exists.
  * Otherwise, the phone number's region will be returned, with optionally some more detailed
  * information.
  *
  * <p>For example, for a user from the region "US" (United States), we would show "Mountain View,
  * CA" for a particular number, omitting the United States from the description. For a user from
  * the United Kingdom (region "GB"), for the same number we may show "Mountain View, CA, United
  * States" or even just "United States".
  *
  * @param PhoneNumber $number a valid phone number for which we want to get a text description
  * @param string $locale the language code for which the description should be written
  * @param string $userRegion the region code for a given user. This region will be omitted from the
  *     description if the phone number comes from this region. It is a two-letter uppercase ISO
  *     country code as defined by ISO 3166-1.
  * @return string a text description for the given language code for the given phone number
  */
 public function getDescriptionForValidNumber(PhoneNumber $number, $locale, $userRegion = null)
 {
     // If the user region matches the number's region, then we just show the lower-level
     // description, if one exists - if no description exists, we will show the region(country) name
     // for the number.
     $regionCode = $this->phoneUtil->getRegionCodeForNumber($number);
     if ($userRegion == null || $userRegion == $regionCode) {
         $languageStr = Locale::getPrimaryLanguage($locale);
         $scriptStr = "";
         $regionStr = Locale::getRegion($locale);
         $mobileToken = $this->phoneUtil->getCountryMobileToken($number->getCountryCode());
         $nationalNumber = $this->phoneUtil->getNationalSignificantNumber($number);
         if ($mobileToken !== "" && !strncmp($nationalNumber, $mobileToken, strlen($mobileToken))) {
             // In some countries, eg. Argentina, mobile numbers have a mobile token before the national
             // destination code, this should be removed before geocoding.
             $nationalNumber = substr($nationalNumber, strlen($mobileToken));
             $copiedNumber = new PhoneNumber();
             $copiedNumber->setCountryCode($number->getCountryCode());
             $copiedNumber->setNationalNumber($nationalNumber);
             if (substr($nationalNumber, 0, 1) == "0") {
                 $copiedNumber->setItalianLeadingZero(true);
             }
             $areaDescription = $this->prefixFileReader->getDescriptionForNumber($copiedNumber, $languageStr, $scriptStr, $regionStr);
         } else {
             $areaDescription = $this->prefixFileReader->getDescriptionForNumber($number, $languageStr, $scriptStr, $regionStr);
         }
         return strlen($areaDescription) > 0 ? $areaDescription : $this->getCountryNameForNumber($number, $locale);
     }
     // Otherwise, we just show the region(country) name for now.
     return $this->getRegionDisplayName($regionCode, $locale);
     // TODO: Concatenate the lower-level and country-name information in an appropriate
     // way for each language.
 }