PHP 클래스 libphonenumber\ShortNumberInfo

파일 보기 프로젝트 열기: giggsey/libphonenumber-for-php 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$countryCallingCodeToRegionCodeMap
$countryCodeToNonGeographicalMetadataMap
$currentFilePrefix
$instance ShortNumberInfo
$matcherAPI libphonenumber\MatcherAPIInterface
$regionToMetadataMap
$regionsWhereEmergencyNumbersMustBeExact

공개 메소드들

메소드 설명
connectsToEmergencyNumber ( string $number, string $regionCode ) : boolean Returns true if the given number, exactly as dialed, might be used to connect to an emergency service in the given region.
getExampleShortNumber ( $regionCode ) : string Gets a valid short number for the specified region.
getExampleShortNumberForCost ( string $regionCode, integer $cost ) : string Gets a valid short number for the specified cost category.
getExpectedCost ( PhoneNumber $number ) : integer Gets the expected cost category of a short number (however, nothing is implied about its validity). If the country calling code is unique to a region, this method behaves exactly the same as {@link #getExpectedCostForRegion(PhoneNumber, String)}. However, if the country calling code is shared by multiple regions, then it returns the highest cost in the sequence PREMIUM_RATE, UNKNOWN_COST, STANDARD_RATE, TOLL_FREE. The reason for the position of UNKNOWN_COST in this order is that if a number is UNKNOWN_COST in one region but STANDARD_RATE or TOLL_FREE in another, its expected cost cannot be estimated as one of the latter since it might be a PREMIUM_RATE number.
getExpectedCostForRegion ( PhoneNumber | string $number, string $regionDialingFrom ) : integer Gets the expected cost category of a short number when dialled from a region (however, nothing is implied about its validity). If it is important that the number is valid, then its validity must first be checked using {@link isValidShortNumberForRegion}. Note that emergency numbers are always considered toll-free.
getInstance ( ) : ShortNumberInfo Returns the singleton instance of ShortNumberInfo
getMetadataForRegion ( $regionCode ) : PhoneMetadata | null
getSupportedRegions ( )
isCarrierSpecific ( PhoneNumber $number ) : boolean Given a valid short number, determines whether it is carrier-specific (however, nothing is implied about its validity). If it is important that the number is valid, then its validity must first be checked using {@link isValidShortNumber} or {@link #isValidShortNumberForRegion}.
isEmergencyNumber ( string $number, string $regionCode ) : boolean Returns true if the given number exactly matches an emergency service number in the given region.
isPossibleShortNumber ( PhoneNumber $number ) : boolean Check whether a short number is a possible number. If a country calling code is shared by multiple regions, this returns true if it's possible in any of them. This provides a more lenient check than {@link #isValidShortNumber}. See {@link #IsPossibleShortNumberForRegion(PhoneNumber, String)} for details.
isPossibleShortNumberForRegion ( PhoneNumber | string $shortNumber, string $regionDialingFrom ) : boolean Check whether a short number is a possible number when dialled from a region, given the number in the form of a string, and the region where the number is dialled from. This provides a more lenient check than {@link #isValidShortNumber}.
isValidShortNumber ( PhoneNumber $number ) : boolean Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns true if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. See {@link #isValidShortNumberForRegion(PhoneNumber, String)} for details.
isValidShortNumberForRegion ( PhoneNumber | string $number, string $regionDialingFrom ) : boolean Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself.
resetInstance ( )

보호된 메소드들

메소드 설명
__construct ( libphonenumber\MatcherAPIInterface $matcherAPI )
getNationalSignificantNumber ( PhoneNumber $number ) : string Gets the national significant number of the a phone number. Note a national significant number doesn't contain a national prefix or any formatting.
getRegionCodeForShortNumberFromRegionList ( PhoneNumber $number, $regionCodes ) : String | null Helper method to get the region code for a given phone number, from a list of possible region codes. If the list contains more than one region, the first region for which the number is valid is returned.
getRegionCodesForCountryCode ( integer $countryCallingCode ) : array Returns a list with teh region codes that match the specific country calling code. For non-geographical country calling codes, the region code 001 is returned. Also, in the case of no region code being found, an empty list is returned.
loadMetadataFromFile ( $filePrefix, $regionCode, $countryCallingCode )
matchesEmergencyNumberHelper ( string $number, string $regionCode, boolean $allowPrefixMatch ) : boolean
matchesPossibleNumberAndNationalNumber ( string $number, PhoneNumberDesc $numberDesc ) : boolean TODO: Once we have benchmarked ShortnumberInfo, consider if it is worth keeping this performance optimization.
regionDialingFromMatchesNumber ( PhoneNumber $number, string $regionDialingFrom ) : boolean Helper method to check that the country calling code of the number matches the region it's being dialed from.

메소드 상세

__construct() 보호된 메소드

protected __construct ( libphonenumber\MatcherAPIInterface $matcherAPI )
$matcherAPI libphonenumber\MatcherAPIInterface

connectsToEmergencyNumber() 공개 메소드

This method accepts a string, rather than a PhoneNumber, because it needs to distinguish cases such as "+1 911" and "911", where the former may not connect to an emergency service in all cases but the latter would. This method takes into account cases where the number might contain formatting, or might have additional digits appended (when it is okay to do that in the specified region).

public connectsToEmergencyNumber ( string $number, string $regionCode ) : boolean
$number string the phone number to test
$regionCode string the region where the phone number if being dialled
리턴 boolean whether the number might be used to connect to an emergency service in the given region

getExampleShortNumber() 공개 메소드

Gets a valid short number for the specified region.
public getExampleShortNumber ( $regionCode ) : string
$regionCode String the region for which an example short number is needed
리턴 string a valid short number for the specified region. Returns an empty string when the metadata does not contain such information.

getExampleShortNumberForCost() 공개 메소드

Gets a valid short number for the specified cost category.
public getExampleShortNumberForCost ( string $regionCode, integer $cost ) : string
$regionCode string the region for which an example short number is needed
$cost integer the cost category of number that is needed
리턴 string a valid short number for the specified region and cost category. Returns an empty string when the metadata does not contain such information, or the cost is UNKNOWN_COST.

getExpectedCost() 공개 메소드

For example, if a number is STANDARD_RATE in the US, but TOLL_FREE in Canada, the expected cost returned by this method will be STANDARD_RATE, since the NANPA countries share the same country calling code.

Note: If the region from which the number is dialed is known, it is highly preferable to call {@link #getExpectedCostForRegion(PhoneNumber, String)} instead.
public getExpectedCost ( PhoneNumber $number ) : integer
$number PhoneNumber the short number for which we want to know the expected cost category
리턴 integer the highest expected cost category of the short number in the region(s) with the given country calling code

getExpectedCostForRegion() 공개 메소드

Example usage:
{@code $shortInfo = ShortNumberInfo::getInstance();
$shortNumber = "110";
$regionCode = "FR";
if ($shortInfo->isValidShortNumberForRegion($shortNumber, $regionCode)) {
    $cost = $shortInfo->getExpectedCostForRegion($shortNumber, $regionCode);
Do something with the cost information here.}}
public getExpectedCostForRegion ( PhoneNumber | string $number, string $regionDialingFrom ) : integer
$number PhoneNumber | string the short number for which we want to know the expected cost category, as a string
$regionDialingFrom string the region from which the number is dialed
리턴 integer the expected cost category for that region of the short number. Returns UNKNOWN_COST if the number does not match a cost category. Note that an invalid number may match any cost category.

getInstance() 공개 정적인 메소드

Returns the singleton instance of ShortNumberInfo
public static getInstance ( ) : ShortNumberInfo
리턴 ShortNumberInfo

getMetadataForRegion() 공개 메소드

public getMetadataForRegion ( $regionCode ) : PhoneMetadata | null
$regionCode
리턴 PhoneMetadata | null

getNationalSignificantNumber() 보호된 메소드

This is a temporary duplicate of the {@code getNationalSignificantNumber} method from {@code PhoneNumberUtil}. Ultimately a canonical static version should exist in a separate utility class (to prevent {@code ShortNumberInfo} needing to depend on PhoneNumberUtil).

protected getNationalSignificantNumber ( PhoneNumber $number ) : string
$number PhoneNumber the phone number for which the national significant number is needed
리턴 string the national significant number of the PhoneNumber object passed in

getRegionCodeForShortNumberFromRegionList() 보호된 메소드

Helper method to get the region code for a given phone number, from a list of possible region codes. If the list contains more than one region, the first region for which the number is valid is returned.
protected getRegionCodeForShortNumberFromRegionList ( PhoneNumber $number, $regionCodes ) : String | null
$number PhoneNumber
$regionCodes
리턴 String | null Region Code (or null if none are found)

getRegionCodesForCountryCode() 보호된 메소드

Returns a list with teh region codes that match the specific country calling code. For non-geographical country calling codes, the region code 001 is returned. Also, in the case of no region code being found, an empty list is returned.
protected getRegionCodesForCountryCode ( integer $countryCallingCode ) : array
$countryCallingCode integer
리턴 array

getSupportedRegions() 공개 메소드

public getSupportedRegions ( )

isCarrierSpecific() 공개 메소드

Given a valid short number, determines whether it is carrier-specific (however, nothing is implied about its validity). If it is important that the number is valid, then its validity must first be checked using {@link isValidShortNumber} or {@link #isValidShortNumberForRegion}.
public isCarrierSpecific ( PhoneNumber $number ) : boolean
$number PhoneNumber the valid short number to check
리턴 boolean whether the short number is carrier-specific (assuming the input was a valid short number).

isEmergencyNumber() 공개 메소드

This method takes into account cases where the number might contain formatting, but doesn't allow additional digits to be appended. Note that {@code isEmergencyNumber(number, region)} implies {@code connectsToEmergencyNumber(number, region)}.

public isEmergencyNumber ( string $number, string $regionCode ) : boolean
$number string the phone number to test
$regionCode string the region where the phone number is being dialled
리턴 boolean whether the number exactly matches an emergency services number in the given region

isPossibleShortNumber() 공개 메소드

Check whether a short number is a possible number. If a country calling code is shared by multiple regions, this returns true if it's possible in any of them. This provides a more lenient check than {@link #isValidShortNumber}. See {@link #IsPossibleShortNumberForRegion(PhoneNumber, String)} for details.
public isPossibleShortNumber ( PhoneNumber $number ) : boolean
$number PhoneNumber PhoneNumber the short number to check
리턴 boolean whether the number is a possible short number

isPossibleShortNumberForRegion() 공개 메소드

Check whether a short number is a possible number when dialled from a region, given the number in the form of a string, and the region where the number is dialled from. This provides a more lenient check than {@link #isValidShortNumber}.
public isPossibleShortNumberForRegion ( PhoneNumber | string $shortNumber, string $regionDialingFrom ) : boolean
$shortNumber PhoneNumber | string The short number to check
$regionDialingFrom string Region dialing From
리턴 boolean whether the number is a possible short number

isValidShortNumber() 공개 메소드

Tests whether a short number matches a valid pattern. If a country calling code is shared by multiple regions, this returns true if it's valid in any of them. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself. See {@link #isValidShortNumberForRegion(PhoneNumber, String)} for details.
public isValidShortNumber ( PhoneNumber $number ) : boolean
$number PhoneNumber PhoneNumber the short number for which we want to test the validity
리턴 boolean whether the short number matches a valid pattern

isValidShortNumberForRegion() 공개 메소드

Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify the number is actually in use, which is impossible to tell by just looking at the number itself.
public isValidShortNumberForRegion ( PhoneNumber | string $number, string $regionDialingFrom ) : boolean
$number PhoneNumber | string The Short number for which we want to test the validity
$regionDialingFrom string the region from which the number is dialed
리턴 boolean whether the short number matches a valid pattern

loadMetadataFromFile() 보호된 메소드

protected loadMetadataFromFile ( $filePrefix, $regionCode, $countryCallingCode )

matchesEmergencyNumberHelper() 보호된 메소드

protected matchesEmergencyNumberHelper ( string $number, string $regionCode, boolean $allowPrefixMatch ) : boolean
$number string
$regionCode string
$allowPrefixMatch boolean
리턴 boolean

matchesPossibleNumberAndNationalNumber() 보호된 메소드

TODO: Once we have benchmarked ShortnumberInfo, consider if it is worth keeping this performance optimization.
protected matchesPossibleNumberAndNationalNumber ( string $number, PhoneNumberDesc $numberDesc ) : boolean
$number string
$numberDesc PhoneNumberDesc
리턴 boolean

regionDialingFromMatchesNumber() 보호된 메소드

Helper method to check that the country calling code of the number matches the region it's being dialed from.
protected regionDialingFromMatchesNumber ( PhoneNumber $number, string $regionDialingFrom ) : boolean
$number PhoneNumber
$regionDialingFrom string
리턴 boolean

resetInstance() 공개 정적인 메소드

public static resetInstance ( )

프로퍼티 상세

$countryCallingCodeToRegionCodeMap 보호되어 있는 프로퍼티

protected $countryCallingCodeToRegionCodeMap

$countryCodeToNonGeographicalMetadataMap 보호되어 있는 프로퍼티

protected $countryCodeToNonGeographicalMetadataMap

$currentFilePrefix 보호되어 있는 프로퍼티

protected $currentFilePrefix

$instance 보호되어 있는 정적으로 프로퍼티

protected static ShortNumberInfo,libphonenumber $instance
리턴 ShortNumberInfo

$matcherAPI 보호되어 있는 프로퍼티

protected MatcherAPIInterface,libphonenumber $matcherAPI
리턴 libphonenumber\MatcherAPIInterface

$regionToMetadataMap 보호되어 있는 프로퍼티

protected $regionToMetadataMap

$regionsWhereEmergencyNumbersMustBeExact 보호되어 있는 정적으로 프로퍼티

protected static $regionsWhereEmergencyNumbersMustBeExact