public function setUp() { self::$plusSymbol = pack('H*', 'efbc8b'); PhoneNumberUtil::resetInstance(); ShortNumberInfo::resetInstance(); $this->phoneUtil = PhoneNumberUtil::getInstance(PhoneNumberUtilTest::TEST_META_DATA_FILE_PREFIX, CountryCodeToRegionCodeMapForTesting::$countryCodeToRegionCodeMapForTesting); $this->shortInfo = ShortNumberInfo::getInstance(); }
public function __construct($number, array $config = NULL) { $this->number = $number; $this->config = Kohana::$config->load('phonenumber')->as_array(); if (!empty($config)) { $this->config = Arr::merge($this->config, $config); } if (!isset($this->config['country'])) { $this->config['country'] = ''; } if (empty($this->config['country'])) { throw new Kohana_Exception('Country code is required'); } $this->config['country'] = strtoupper($this->config['country']); if (!isset($this->config['language'])) { $this->config['language'] = ''; } if (!isset($this->config['region'])) { $this->config['region'] = ''; } $this->config['language'] = empty($this->config['language']) ? 'en' : strtolower($this->config['language']); $this->config['region'] = empty($this->config['region']) ? NULL : strtoupper($this->config['region']); $this->phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance(); $this->shortNumberInfo = \libphonenumber\ShortNumberInfo::getInstance(); $this->phoneNumberGeocoder = \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance(); if (!empty($number)) { try { $this->phoneNumber = $this->phoneNumberUtil->parse($number, $this->config['country'], NULL, TRUE); $this->possibleNumber = $this->phoneNumberUtil->isPossibleNumber($this->phoneNumber); $this->isPossibleNumberWithReason = $this->phoneNumberUtil->isPossibleNumberWithReason($this->phoneNumber); $this->validNumber = $this->phoneNumberUtil->isValidNumber($this->phoneNumber); $this->validNumberForRegion = $this->phoneNumberUtil->isValidNumberForRegion($this->phoneNumber, $input['country']); $this->phoneNumberRegion = $this->phoneNumberUtil->getRegionCodeForNumber($this->phoneNumber); $this->phoneNumberType = $this->phoneNumberUtil->getNumberType($this->phoneNumber); $this->geolocation = $this->phoneNumberGeocoder->getDescriptionForNumber($this->phoneNumber, $this->config['language'], $this->config['region']); $this->phoneNumberToCarrierInfo = \libphonenumber\PhoneNumberToCarrierMapper::getInstance()->getNameForNumber($this->phoneNumber, $this->config['language']); $this->timezone = \libphonenumber\PhoneNumberToTimeZonesMapper::getInstance()->getTimeZonesForNumber($this->phoneNumber); } catch (\libphonenumber\NumberParseException $e) { throw new Kohana_Exception(':error', array(':error' => $e->getMessage()), $e->getCode()); } } }
public function shortNumberRegionList() { $returnList = array(); PhoneNumberUtil::resetInstance(); $phoneUtil = PhoneNumberUtil::getInstance(); $shortNumberInfo = ShortNumberInfo::getInstance($phoneUtil); foreach ($shortNumberInfo->getSupportedRegions() as $regionCode) { $returnList[] = array($regionCode); } return $returnList; }
public function testIssue64WithoutPhoneNumberUtilresetInstance() { PhoneNumberUtil::resetInstance(); $sortNumberUtil = ShortNumberInfo::getInstance(); $this->assertTrue($sortNumberUtil->isEmergencyNumber('999', 'GB')); }
public function testShortNumberInfoIsPossibleShortNumberForRegionWithRegionMissingFromCodeSet() { $exampleNumber = $this->getExampleNumber('NE'); $shortNumberInfo = ShortNumberInfo::getInstance(); $this->assertFalse($shortNumberInfo->isPossibleShortNumberForRegion($exampleNumber, 'NE')); }