• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP libphonenumber\PhoneNumberUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中libphonenumber\PhoneNumberUtil的典型用法代码示例。如果您正苦于以下问题:PHP PhoneNumberUtil类的具体用法?PHP PhoneNumberUtil怎么用?PHP PhoneNumberUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PhoneNumberUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: testDenormalize

 public function testDenormalize()
 {
     $obj = $this->numberUtil->parse('+31508100210', PhoneNumberUtil::UNKNOWN_REGION);
     $str = '+31508100210';
     self::assertEquals($obj, $this->normalizer->denormalize($str, 'json'));
     self::assertEquals($obj, $this->normalizer->denormalize($str, 'xml'));
 }
开发者ID:a-mayer,项目名称:boekkooi-broadway,代码行数:7,代码来源:PhoneNumberNormalizerTest.php


示例2: getTimeZonesForNumber

 /**
  * As per {@link #getTimeZonesForGeographicalNumber(PhoneNumber)} but explicitly checks
  * the validity of the number passed in.
  *
  * @param $number PhoneNumber the phone number for which we want to get the time zones to which it belongs
  * @return array a list of the corresponding time zones or a single element list with the default
  *     unknown time zone if no other time zone was found or if the number was invalid
  */
 public function getTimeZonesForNumber(PhoneNumber $number)
 {
     $numberType = $this->phoneUtil->getNumberType($number);
     if ($numberType === PhoneNumberType::UNKNOWN) {
         return $this->unknownTimeZoneList;
     } elseif (!!PhoneNumberUtil::getInstance()->isNumberGeographical($numberType, $number->getCountryCode())) {
         return $this->getCountryLevelTimeZonesforNumber($number);
     }
     return $this->getTimeZonesForGeographicalNumber($number);
 }
开发者ID:giggsey,项目名称:libphonenumber-for-php,代码行数:18,代码来源:PhoneNumberToTimeZonesMapper.php


示例3: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (self::WIDGET_COUNTRY_CHOICE === $options['widget']) {
         $util = PhoneNumberUtil::getInstance();
         $countries = array();
         if (is_array($options['country_choices'])) {
             foreach ($options['country_choices'] as $country) {
                 $code = $util->getCountryCodeForRegion($country);
                 if ($code) {
                     $countries[$country] = $code;
                 }
             }
         }
         if (empty($countries)) {
             foreach ($util->getSupportedRegions() as $country) {
                 $countries[$country] = $util->getCountryCodeForRegion($country);
             }
         }
         $countryChoices = array();
         foreach (Intl::getRegionBundle()->getCountryNames() as $region => $name) {
             if (false === isset($countries[$region])) {
                 continue;
             }
             $countryChoices[$region] = sprintf('%s (+%s)', $name, $countries[$region]);
         }
         $countryOptions = $numberOptions = array('error_bubbling' => true, 'required' => $options['required'], 'disabled' => $options['disabled'], 'translation_domain' => $options['translation_domain']);
         $countryOptions['required'] = true;
         $countryOptions['choices'] = $countryChoices;
         $countryOptions['preferred_choices'] = $options['preferred_country_choices'];
         $countryOptions['choice_translation_domain'] = false;
         $builder->add('country', 'choice', $countryOptions)->add('number', 'text', $numberOptions)->addViewTransformer(new PhoneNumberToArrayTransformer(array_keys($countryChoices)));
     } else {
         $builder->addViewTransformer(new PhoneNumberToStringTransformer($options['default_region'], $options['format']));
     }
 }
开发者ID:skafandri,项目名称:phone-number-bundle,代码行数:38,代码来源:PhoneNumberType.php


示例4: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     PhoneNumberUtil::resetInstance();
     self::$AO_MOBILE1 = new PhoneNumber();
     self::$AO_MOBILE1->setCountryCode(244)->setNationalNumber(917654321);
     self::$AO_MOBILE2 = new PhoneNumber();
     self::$AO_MOBILE2->setCountryCode(244)->setNationalNumber(927654321);
     self::$AO_FIXED1 = new PhoneNumber();
     self::$AO_FIXED1->setCountryCode(244)->setNationalNumber(22254321);
     self::$AO_FIXED2 = new PhoneNumber();
     self::$AO_FIXED2->setCountryCode(244)->setNationalNumber(26254321);
     self::$AO_INVALID_NUMBER = new PhoneNumber();
     self::$AO_INVALID_NUMBER->setCountryCode(244)->setNationalNumber(101234);
     self::$UK_MOBILE1 = new PhoneNumber();
     self::$UK_MOBILE1->setCountryCode(44)->setNationalNumber(7387654321);
     self::$UK_MOBILE2 = new PhoneNumber();
     self::$UK_MOBILE2->setCountryCode(44)->setNationalNumber(7487654321);
     self::$UK_FIXED1 = new PhoneNumber();
     self::$UK_FIXED1->setCountryCode(44)->setNationalNumber(1123456789);
     self::$UK_FIXED2 = new PhoneNumber();
     self::$UK_FIXED2->setCountryCode(44)->setNationalNumber(2987654321);
     self::$UK_INVALID_NUMBER = new PhoneNumber();
     self::$UK_INVALID_NUMBER->setCountryCode(44)->setNationalNumber(7301234);
     self::$UK_PAGER = new PhoneNumber();
     self::$UK_PAGER->setCountryCode(44)->setNationalNumber(7601234567);
     self::$US_FIXED_OR_MOBILE = new PhoneNumber();
     self::$US_FIXED_OR_MOBILE->setCountryCode(1)->setNationalNumber(6502123456);
     self::$NUMBER_WITH_INVALID_COUNTRY_CODE = new PhoneNumber();
     self::$NUMBER_WITH_INVALID_COUNTRY_CODE->setCountryCode(999)->setNationalNumber(2423651234);
     self::$INTERNATIONAL_TOLL_FREE = new PhoneNumber();
     self::$INTERNATIONAL_TOLL_FREE->setCountryCode(800)->setNationalNumber(12345678);
 }
开发者ID:RonLab1987,项目名称:ride-workshop,代码行数:32,代码来源:PhoneNumberToCarrierMapperTest.php


示例5: validatePhone

 /**
  * Validates a phone number.
  */
 public function validatePhone($attribute, $value, $parameters, $validator)
 {
     $this->attribute = $attribute;
     $this->data = $validator->getData();
     $this->parameters = array_map('strtoupper', $parameters);
     $this->determineCountries();
     $this->determineTypes();
     $this->checkLeftoverParameters();
     $phoneUtil = PhoneNumberUtil::getInstance();
     // Perform validation.
     foreach ($this->allowedCountries as $country) {
         try {
             // For default countries or country field, the following throws NumberParseException if
             // not parsed correctly against the supplied country.
             // For automatic detection: tries to discover the country code using from the number itself.
             $phoneProto = $phoneUtil->parse($value, $country);
             // For automatic detection, the number should have a country code.
             // Check if type is allowed.
             if ($phoneProto->hasCountryCode() && empty($this->allowedTypes) || in_array($phoneUtil->getNumberType($phoneProto), $this->allowedTypes)) {
                 // Automatic detection:
                 if ($country == 'ZZ') {
                     // Validate if the international phone number is valid for its contained country.
                     return $phoneUtil->isValidNumber($phoneProto);
                 }
                 // Force validation of number against the specified country.
                 return $phoneUtil->isValidNumberForRegion($phoneProto, $country);
             }
         } catch (NumberParseException $e) {
             // Proceed to default validation error.
         }
     }
     return false;
 }
开发者ID:MehmetNuri,项目名称:faveo-helpdesk,代码行数:36,代码来源:PhoneValidator.php


示例6: testIssue76

 /**
  * @expectedException \libphonenumber\NumberParseException
  * @expectedExceptionCode 1
  * @expectedExceptionMessage The string supplied did not seem to be a phone number.
  */
 public function testIssue76()
 {
     $number = '[email protected]';
     $region = 'DE';
     $util = PhoneNumberUtil::getInstance();
     $util->parse($number, $region);
 }
开发者ID:ayurmedia,项目名称:faveo-helpdesk,代码行数:12,代码来源:Issue76Test.php


示例7: getTargetPhoneNumber

 public function getTargetPhoneNumber($defaultRegion)
 {
     if ($this->getTargetUri() === null || !preg_match('/^sip:(\\d+)@/', $this->getTargetUri(), $matches)) {
         return null;
     }
     return PhoneNumberUtil::getInstance()->parse($matches[1], $defaultRegion);
 }
开发者ID:pigulla,项目名称:owncloud-sipgate,代码行数:7,代码来源:itemizedentry.php


示例8: cleanPhone

 /**
  * Clean phone number for Twilio
  * @param string $phone
  * @return string
  */
 protected function cleanPhone($phone, $useTimezone = true)
 {
     // if Phone number is not in E164 try to parse it
     if (!preg_match('/^\\+.\\d+$/', $phone)) {
         if ($useTimezone) {
             $phoneUtil = PhoneNumberUtil::getInstance();
             try {
                 // Get country code using configure timezone
                 $tz = Carbon::now()->getTimezone();
                 $country_code = array_get($tz->getLocation(), 'country_code', 'US');
                 // Parse phone number
                 $numberProto = $phoneUtil->parse($phone, $country_code);
                 // Return phone
                 return $phoneUtil->format($numberProto, PhoneNumberFormat::E164);
             } catch (\libphonenumber\NumberParseException $e) {
                 // Invalid phone let twilio complain :D
                 return '';
             }
         }
         // Just add missing plus sing
         return '+' . $phone;
     } else {
         return $phone;
     }
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:30,代码来源:ChannelSMS.php


示例9: getPhoneNumberService

 /**
  * @return mixed
  */
 public function getPhoneNumberService()
 {
     if ($this->phoneNumberService === null) {
         $this->phoneNumberService = PhoneNumberUtil::getInstance();
     }
     return $this->phoneNumberService;
 }
开发者ID:nobesnickr,项目名称:ApiTimesheets,代码行数:10,代码来源:PhoneNumber.php


示例10: getDescriptionForValidNumber

 /**
  * 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 = PhoneNumberUtil::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));
             $region = $this->phoneUtil->getRegionCodeForCountryCode($number->getCountryCode());
             try {
                 $copiedNumber = $this->phoneUtil->parse($nationalNumber, $region);
             } catch (NumberParseException $e) {
                 // If this happens, just reuse what we had.
                 $copiedNumber = $number;
             }
             $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.
 }
开发者ID:giggsey,项目名称:libphonenumber-for-php,代码行数:61,代码来源:PhoneNumberOfflineGeocoder.php


示例11: register

 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('libphonenumber', function ($app) {
         return PhoneNumberUtil::getInstance();
     });
     $this->app->alias('libphonenumber', 'libphonenumber\\PhoneNumberUtil');
 }
开发者ID:propaganistas,项目名称:laravel-phone,代码行数:12,代码来源:LaravelPhoneServiceProvider.php


示例12: testChineseCarrierLookup

 public function testChineseCarrierLookup()
 {
     $number = $this->phoneUtil->parse("+86 150 3657 7264", "CN");
     $carrier = PhoneNumberToCarrierMapper::getInstance();
     $location = $carrier->getNameForNumber($number, "en");
     $this->assertEquals("China Mobile", $location);
 }
开发者ID:ayurmedia,项目名称:faveo-helpdesk,代码行数:7,代码来源:Issue44Test.php


示例13: testIsValidNumberForRegion

 public function testIsValidNumberForRegion()
 {
     $number = "+33 6 76 83 51 85";
     $region = "DE";
     $phoneNumber = $this->phoneUtil->parse($number, $region);
     $this->assertFalse($this->phoneUtil->isValidNumberForRegion($phoneNumber, "DE"));
 }
开发者ID:RonLab1987,项目名称:ride-workshop,代码行数:7,代码来源:Issue34Test.php


示例14: testKWMobileNumber

 public function testKWMobileNumber()
 {
     $number = "51440519";
     $phoneNumber = $this->phoneUtil->parse($number, "KW");
     $this->assertTrue($this->phoneUtil->isValidNumber($phoneNumber));
     $this->assertEquals(PhoneNumberType::MOBILE, $this->phoneUtil->getNumberType($phoneNumber));
 }
开发者ID:ayurmedia,项目名称:faveo-helpdesk,代码行数:7,代码来源:Issue14Test.php


示例15: filter

 public function filter($value)
 {
     try {
         $NumberProto = $this->libPhoneNumber->parse($value, $this->getCountry());
     } catch (NumberParseException $e) {
         return $value;
     }
     return $this->libPhoneNumber->format($NumberProto, PhoneNumberFormat::E164);
 }
开发者ID:uthando-cms,项目名称:uthando-common,代码行数:9,代码来源:PhoneNumber.php


示例16: testSerializingPhoneNumber

 public function testSerializingPhoneNumber()
 {
     $number = "+441174900000";
     $region = "GB";
     $phoneNumber = $this->phoneUtil->parse($number, $region);
     $serializedString = serialize($phoneNumber);
     $phoneObject2 = unserialize($serializedString);
     $this->assertTrue($phoneObject2->equals($phoneNumber));
 }
开发者ID:RonLab1987,项目名称:ride-workshop,代码行数:9,代码来源:Issue35Test.php


示例17: testLocales

 /**
  * @dataProvider localeList
  * @param string $regionCode
  * @param string $countryName
  */
 public function testLocales($regionCode, $countryName)
 {
     if (!in_array($regionCode, $this->phoneUtil->getSupportedRegions())) {
         $this->markTestSkipped("{$regionCode} is not supported");
     }
     $phoneNumber = $this->phoneUtil->getExampleNumberForType($regionCode, PhoneNumberType::FIXED_LINE_OR_MOBILE);
     $this->assertContains($regionCode, CountryCodeToRegionCodeMap::$countryCodeToRegionCodeMap[$phoneNumber->getCountryCode()]);
     $this->assertEquals($regionCode, $this->phoneUtil->getRegionCodeForNumber($phoneNumber));
     $this->assertEquals($countryName, $this->geocoder->getDescriptionForValidNumber($phoneNumber, 'en', 'ZZ'), "Checking {$phoneNumber} is part of {$countryName}");
 }
开发者ID:wakeless,项目名称:libphonenumber-for-php,代码行数:15,代码来源:LocaleTest.php


示例18: getTimeZonesForNumber

 /**
  * As per {@link #getTimeZonesForGeographicalNumber(PhoneNumber)} but explicitly checks
  * the validity of the number passed in.
  *
  * @param $number PhoneNumber the phone number for which we want to get the time zones to which it belongs
  * @return array a list of the corresponding time zones or a single element list with the default
  *     unknown time zone if no other time zone was found or if the number was invalid
  */
 public function getTimeZonesForNumber(PhoneNumber $number)
 {
     $numberType = $this->phoneUtil->getNumberType($number);
     if ($numberType === PhoneNumberType::UNKNOWN) {
         return $this->unknownTimeZoneList;
     } elseif (!$this->canBeGeocoded($numberType)) {
         return $this->getCountryLevelTimeZonesforNumber($number);
     }
     return $this->getTimeZonesForGeographicalNumber($number);
 }
开发者ID:RonLab1987,项目名称:ride-workshop,代码行数:18,代码来源:PhoneNumberToTimeZonesMapper.php


示例19: render

 /**
  * Returns a plain phonenumber readable for mobile devices
  *
  * @param string $phoneNumber Formatted Phone Number
  * @return string
  */
 public function render($phoneNumber)
 {
     $plainPhoneNumber = '';
     if ($phoneNumber) {
         /** @var \libphonenumber\PhoneNumber $plainPhoneNumberPrototype */
         $plainPhoneNumberPrototype = $this->phoneNumberUtility->parse($phoneNumber, 'DE');
         $plainPhoneNumber = $this->phoneNumberUtility->format($plainPhoneNumberPrototype, \libphonenumber\PhoneNumberFormat::RFC3966);
     }
     return $plainPhoneNumber;
 }
开发者ID:subugoe,项目名称:substaff,代码行数:16,代码来源:PlainPhoneNumberViewHelper.php


示例20: format

 /**
  * Format a phone number.
  *
  * @param PhoneNumber $phoneNumber Phone number.
  * @param int|string  $format      Format, or format constant name.
  *
  * @return string Formatted phone number.
  *
  * @throws InvalidArgumentException If an argument is invalid.
  */
 public function format(PhoneNumber $phoneNumber, $format = PhoneNumberFormat::INTERNATIONAL)
 {
     if (true === is_string($format)) {
         $constant = '\\libphonenumber\\PhoneNumberFormat::' . $format;
         if (false === defined($constant)) {
             throw new InvalidArgumentException('The format must be either a constant value or name in libphonenumber\\PhoneNumberFormat');
         }
         $format = constant('\\libphonenumber\\PhoneNumberFormat::' . $format);
     }
     return $this->phoneNumberUtil->format($phoneNumber, $format);
 }
开发者ID:clavier-souris,项目名称:phone-number-bundle,代码行数:21,代码来源:PhoneNumberFormatHelper.php



注:本文中的libphonenumber\PhoneNumberUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Library\Application类代码示例发布时间:2022-05-23
下一篇:
PHP Request\Init类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap