getNationalNumber() public method

Returns the country code of this phone number.
public getNationalNumber ( ) : string | null
return string | null The national number, or null if not set.
 /**
  * @param Message     $message
  * @param PhoneNumber $recipient
  * @throws SenderException
  * @return bool
  */
 public function send(Message $message, PhoneNumber $recipient)
 {
     $params = ['api_key' => $this->apiKey, 'api_secret' => $this->apiSecret, 'from' => $this->senderName, 'to' => $recipient->getCountryCode() . $recipient->getNationalNumber(), 'text' => $message->getContent(), 'type' => $message->getType() === Message::TYPE_UNICODE ? "unicode" : "text"];
     $url = self::NEXTMO_ENDPOINT . '?' . http_build_query($params);
     $response = $this->getResponse($url);
     if (false === isset($response['messages'])) {
         throw new SenderException('Invalid nexmo response: ' . var_export($response, true));
     }
     foreach ($response['messages'] as $message) {
         if ($message['status'] !== "0") {
             throw new SenderException($message['error-text'], $message['status']);
         }
     }
     return true;
 }
 private function parse()
 {
     if ($this->phoneNumberProto) {
         // from phoneNumberProto
         $this->country_code = $this->phoneNumberProto->getCountryCode();
         $this->country_code_plus_sign = "+" . $this->country_code;
         $this->national_number = $this->phoneNumberProto->getNationalNumber();
         $this->extension = $this->phoneNumberProto->getExtension();
         $this->country_code_source = $this->phoneNumberProto->getCountryCodeSource();
         if (isset($this->countryCodeSourcesText[$this->country_code_source])) {
             $this->country_code_source_text = $this->countryCodeSourcesText[$this->country_code_source];
         }
         $this->raw_input = $this->phoneNumberProto->getRawInput();
         $this->preferred_domestic_carrier_code = $this->phoneNumberProto->getPreferredDomesticCarrierCode();
         // from validation
         $this->is_possible_number = $this->phoneUtil->isPossibleNumber($this->phoneNumberProto);
         $this->is_valid_number = $this->phoneUtil->isValidNumber($this->phoneNumberProto);
         $this->region_code_for_number = $this->phoneUtil->getRegionCodeForNumber($this->phoneNumberProto);
         $this->number_type = $this->phoneUtil->getNumberType($this->phoneNumberProto);
         $this->number_type_text = $this->phoneUtil->getNumberType($this->phoneNumberProto);
         if (isset($this->phoneNumberTypesText[$this->number_type])) {
             $this->number_type_text = $this->phoneNumberTypesText[$this->number_type];
         } else {
             $this->number_type_text = "OTHER";
         }
         $this->is_mobile_number = in_array($this->number_type, [PhoneNumberType::FIXED_LINE_OR_MOBILE, PhoneNumberType::MOBILE]);
         // from formatting
         $this->format_e164 = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::E164);
         $this->format_international = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::INTERNATIONAL);
         $this->format_national = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::NATIONAL);
         $this->format_rfc3966 = $this->phoneUtil->format($this->phoneNumberProto, PhoneNumberFormat::RFC3966);
         // from additional
         $phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder::getInstance();
         $this->description = $phoneNumberOfflineGeocoder->getDescriptionForNumber($this->phoneNumberProto, 'en');
         $phoneNumberToCarrierMapper = PhoneNumberToCarrierMapper::getInstance();
         $this->carrier_name = $phoneNumberToCarrierMapper->getNameForNumber($this->phoneNumberProto, 'en');
         $phoneNumberToTimeZonesMapper = PhoneNumberToTimeZonesMapper::getInstance();
         $this->timezones = $phoneNumberToTimeZonesMapper->getTimeZonesForNumber($this->phoneNumberProto);
     }
 }
 public function send(Message $message, PhoneNumber $recipient)
 {
     $number = $recipient->getCountryCode() . $recipient->getNationalNumber();
     $text = $message->getContent();
     try {
         $maxLen = $message->getType() === Message::TYPE_ASCII ? self::MAX_LENGTH_ASCII : self::MAX_LENGTH_UNICODE;
         $textPreparedForSms = $this->transport->prepareTextForMessage($text);
         if (mb_strlen($textPreparedForSms) > $maxLen) {
             $text = $this->transport->splitMessage($textPreparedForSms, $maxLen);
             $text = array_map($this->transport, $text);
         }
         if (false === is_array($text)) {
             $text = array($text);
         }
         foreach ($text as $contentPart) {
             $this->sender->sendMessage($number, $contentPart, $this->getTypeForMessage($message));
         }
         return true;
     } catch (MobitexException $e) {
         throw new SenderException($e->getMessage(), $e->getCode(), $e);
     }
 }
 /**
  * Returns a text description in the given language for the given phone number.
  *
  * @param PhoneNumber $number  the phone number for which we want to get a text description
  * @param string $language  two-letter lowercase ISO language codes as defined by ISO 639-1
  * @param string $script  four-letter titlecase (the first letter is uppercase and the rest of the letters
  *     are lowercase) ISO script codes as defined in ISO 15924
  * @param string $region  two-letter uppercase ISO country codes as defined by ISO 3166-1
  * @return string a text description in the given language for the given phone number, or an empty
  *     string if a description is not available
  */
 public function getDescriptionForNumber(PhoneNumber $number, $language, $script, $region)
 {
     $countryCallingCode = $number->getCountryCode();
     // As the NANPA data is split into multiple files covering 3-digit areas, use a phone number
     // prefix of 4 digits for NANPA instead, e.g. 1650.
     $phonePrefix = $countryCallingCode !== 1 ? $countryCallingCode : 1000 + intval($number->getNationalNumber() / 10000000);
     $phonePrefixDescriptions = $this->getPhonePrefixDescriptions($phonePrefix, $language, $script, $region);
     $description = $phonePrefixDescriptions !== null ? $phonePrefixDescriptions->lookup($number) : null;
     // When a location is not available in the requested language, fall back to English.
     if (($description === null || strlen($description) === 0) && $this->mayFallBackToEnglish($language)) {
         $defaultMap = $this->getPhonePrefixDescriptions($phonePrefix, "en", "", "");
         if ($defaultMap === null) {
             return "";
         }
         $description = $defaultMap->lookup($number);
     }
     return $description !== null ? $description : "";
 }
 /**
  * Returns a text description in the given language for the given phone number.
  *
  * @param PhoneNumber $number the phone number for which we want to get a text description
  * @param string $language two-letter lowercase ISO language codes as defined by ISO 639-1
  * @param string $script four-letter titlecase (the first letter is uppercase and the rest of the letters
  *     are lowercase) ISO script codes as defined in ISO 15924
  * @param string $region two-letter uppercase ISO country codes as defined by ISO 3166-1
  * @return string a text description in the given language for the given phone number, or an empty
  *     string if a description is not available
  */
 public function getDescriptionForNumber(PhoneNumber $number, $language, $script, $region)
 {
     $countryCallingCode = $number->getCountryCode();
     // As the NANPA data is split into multiple files covering 3-digit areas, use a phone number
     // prefix of 4 digits for NANPA instead, e.g. 1650.
     if ($countryCallingCode === 1) {
         $phonePrefix = 1000 + intval($number->getNationalNumber() / 10000000);
     } elseif ($countryCallingCode === 86) {
         // Split China into multiple files to reduce PHP memory usage
         // @see https://github.com/giggsey/libphonenumber-for-php/issues/44
         $phonePrefix = '86' . substr($number->getNationalNumber(), 0, 3);
     } else {
         $phonePrefix = $countryCallingCode;
     }
     $phonePrefixDescriptions = $this->getPhonePrefixDescriptions($phonePrefix, $language, $script, $region);
     $description = $phonePrefixDescriptions !== null ? $phonePrefixDescriptions->lookup($number) : null;
     // When a location is not available in the requested language, fall back to English.
     if (($description === null || strlen($description) === 0) && $this->mayFallBackToEnglish($language)) {
         $defaultMap = $this->getPhonePrefixDescriptions($phonePrefix, "en", "", "");
         if ($defaultMap === null) {
             return "";
         }
         $description = $defaultMap->lookup($number);
     }
     return $description !== null ? $description : "";
 }
 private function isNationalNumberSuffixOfTheOther(PhoneNumber $firstNumber, PhoneNumber $secondNumber)
 {
     $firstNumberNationalNumber = trim((string) $firstNumber->getNationalNumber());
     $secondNumberNationalNumber = trim((string) $secondNumber->getNationalNumber());
     return $this->stringEndsWithString($firstNumberNationalNumber, $secondNumberNationalNumber) || $this->stringEndsWithString($secondNumberNationalNumber, $firstNumberNationalNumber);
 }
Beispiel #7
0
 /**
  * Returns the national number of this PhoneNumber.
  *
  * The national number is a series of digits.
  *
  * @return string
  */
 public function getNationalNumber()
 {
     return $this->phoneNumber->getNationalNumber();
 }