當前位置: 首頁>>代碼示例>>PHP>>正文


PHP libphonenumber\PhoneNumberUtil類代碼示例

本文整理匯總了PHP中libphonenumber\PhoneNumberUtil的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil類的具體用法?PHP PhoneNumberUtil怎麽用?PHP PhoneNumberUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PhoneNumberUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 = 'Abc811@hotmail.com';
     $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: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的libphonenumber\PhoneNumberUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。