libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getDescriptionForNumber PHP Метод

getDescriptionForNumber() публичный Метод

As per getDescriptionForValidNumber, but explicitly checks the validity of the number passed in.
См. также: getDescriptionForValidNumber
public getDescriptionForNumber ( PhoneNumber $number, string $locale, string $userRegion = null ) : string
$number libphonenumber\PhoneNumber a valid phone number for which we want to get a text description
$locale string the language code for which the description should be written
$userRegion string 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.
Результат string a text description for the given language code for the given phone number, or empty string if the number passed in is invalid
    public function getDescriptionForNumber(PhoneNumber $number, $locale, $userRegion = null)
    {
        $numberType = $this->phoneUtil->getNumberType($number);
        if ($numberType === PhoneNumberType::UNKNOWN) {
            return "";
        } elseif (!$this->phoneUtil->isNumberGeographical($numberType, $number->getCountryCode())) {
            return $this->getCountryNameForNumber($number, $locale);
        }
        return $this->getDescriptionForValidNumber($number, $locale, $userRegion);
    }

Usage Example

Пример #1
0
 /**
  * @param string $number
  * @param string $country
  * @param string|NULL $locale
  * @param string|NULL $userCountry
  *
  * @return string
  *
  * @throws Exceptions\NoValidCountryException
  * @throws Exceptions\NoValidPhoneException
  */
 public function getLocation($number, $country = 'AUTO', $locale = NULL, $userCountry = NULL)
 {
     if ($this->isValid((string) $number, $country)) {
         $country = strtoupper($country);
         if ($userCountry !== NULL) {
             // Check for valid user country
             $userCountry = $this->validateCountry($userCountry);
         }
         // Parse phone number
         $parsed = $this->phoneNumberUtil->parse((string) $number, $country);
         // Determine locale
         $locale = $locale === NULL && $this->translator && method_exists($this->translator, 'getLocale') ? $this->translator->getLocale() : 'en_US';
         // Get phone number location
         return $this->phoneNumberGeocoder->getDescriptionForNumber($parsed, $locale, $userCountry);
     } else {
         throw new Exceptions\NoValidPhoneException('Provided phone number "' . $number . '" is not valid phone number. Provide valid phone number.');
     }
 }
All Usage Examples Of libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getDescriptionForNumber