idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
6,700
|
public function handle ( ) { if ( method_exists ( $ this , 'setup' ) ) { $ this -> setup ( ) ; } $ this -> filterInput ( ) ; $ this -> filterRelations ( ) ; return $ this -> query ; }
|
Handle all filters .
|
6,701
|
public function related ( $ relation , $ column , $ operator = null , $ value = null , $ boolean = 'and' ) { if ( $ column instanceof \ Closure ) { return $ this -> addRelated ( $ relation , $ column ) ; } if ( $ value === null ) { $ value = $ operator ; $ operator = '=' ; } return $ this -> addRelated ( $ relation , function ( $ query ) use ( $ column , $ operator , $ value , $ boolean ) { return $ query -> where ( $ column , $ operator , $ value , $ boolean ) ; } ) ; }
|
Add a where constraint to a relationship .
|
6,702
|
public function filterInput ( ) { foreach ( $ this -> input as $ key => $ val ) { $ method = $ this -> getFilterMethod ( $ key ) ; if ( $ this -> methodIsCallable ( $ method ) ) { $ this -> { $ method } ( $ val ) ; } } }
|
Filter with input array .
|
6,703
|
public function getAllRelations ( ) { if ( count ( $ this -> allRelations ) === 0 ) { $ allRelations = array_merge ( array_keys ( $ this -> relations ) , array_keys ( $ this -> localRelatedFilters ) ) ; foreach ( $ allRelations as $ related ) { $ this -> allRelations [ $ related ] = array_merge ( $ this -> getLocalRelation ( $ related ) , $ this -> getRelatedFilterInput ( $ related ) ) ; } } return $ this -> allRelations ; }
|
Returns all local relations and relations requiring other Model s Filter s .
|
6,704
|
public function filterJoinedRelation ( $ related ) { $ this -> callRelatedLocalSetup ( $ related , $ this -> query ) ; foreach ( $ this -> getLocalRelation ( $ related ) as $ closure ) { $ closure ( $ this -> query ) ; } if ( count ( $ relatedFilterInput = $ this -> getRelatedFilterInput ( $ related ) ) > 0 ) { $ filterClass = $ this -> getRelatedFilter ( $ related ) ; ( new $ filterClass ( $ this -> query , $ relatedFilterInput , false ) ) -> handle ( ) ; } }
|
Run the filter on models that already have their tables joined .
|
6,705
|
public function getJoinedTables ( ) { $ joins = [ ] ; if ( is_array ( $ queryJoins = $ this -> query -> getQuery ( ) -> joins ) ) { $ joins = array_map ( function ( $ join ) { return $ join -> table ; } , $ queryJoins ) ; } return $ joins ; }
|
Gets all the joined tables .
|
6,706
|
public function relationIsJoined ( $ relation ) { if ( $ this -> _joinedTables === null ) { $ this -> _joinedTables = $ this -> getJoinedTables ( ) ; } return in_array ( $ this -> getRelatedTable ( $ relation ) , $ this -> _joinedTables , true ) ; }
|
Checks if the relation to filter s table is already joined .
|
6,707
|
public function filterUnjoinedRelation ( $ related ) { $ this -> query -> whereHas ( $ related , function ( $ q ) use ( $ related ) { $ this -> callRelatedLocalSetup ( $ related , $ q ) ; foreach ( $ this -> getLocalRelation ( $ related ) as $ closure ) { $ closure ( $ q ) ; } if ( count ( $ filterableRelated = $ this -> getRelatedFilterInput ( $ related ) ) > 0 ) { $ q -> filter ( $ filterableRelated ) ; } return $ q ; } ) ; }
|
Filters by a relationship that isn t joined by using that relation s ModelFilter .
|
6,708
|
public function getRelatedFilterInput ( $ related ) { return array_key_exists ( $ related , $ this -> relations ) ? array_only ( $ this -> input , $ this -> relations [ $ related ] ) : [ ] ; }
|
Get input to pass to a related Model s Filter .
|
6,709
|
public function input ( $ key = null , $ default = null ) { if ( $ key === null ) { return $ this -> input ; } return array_key_exists ( $ key , $ this -> input ) ? $ this -> input [ $ key ] : $ default ; }
|
Retrieve input by key or all input as array .
|
6,710
|
public function dropIdSuffix ( $ bool = null ) { if ( $ bool === null ) { return $ this -> drop_id ; } return $ this -> drop_id = $ bool ; }
|
Set to drop _id from input . Mainly for testing .
|
6,711
|
public function convertToCamelCasedMethods ( $ bool = null ) { if ( $ bool === null ) { return $ this -> camel_cased_methods ; } return $ this -> camel_cased_methods = $ bool ; }
|
Convert input to camel_case . Mainly for testing .
|
6,712
|
public function whitelistMethod ( $ method ) { $ this -> blacklist = array_filter ( $ this -> blacklist , function ( $ name ) use ( $ method ) { return $ name !== $ method ; } ) ; return $ this ; }
|
Remove a method from the blacklist .
|
6,713
|
public function methodIsCallable ( $ method ) { return ! $ this -> methodIsBlacklisted ( $ method ) && method_exists ( $ this , $ method ) && ! method_exists ( ModelFilter :: class , $ method ) ; }
|
Check if the method is not blacklisted and callable on the extended class .
|
6,714
|
private function registerMacros ( ) { if ( method_exists ( Relation :: class , 'hasMacro' ) && method_exists ( Relation :: class , 'macro' ) && ! Relation :: hasMacro ( 'paginateFilter' ) && ! Relation :: hasMacro ( 'simplePaginateFilter' ) ) { Relation :: macro ( 'paginateFilter' , function ( ) { $ paginator = call_user_func_array ( [ $ this , 'paginate' ] , func_get_args ( ) ) ; $ paginator -> appends ( $ this -> getRelated ( ) -> filtered ) ; return $ paginator ; } ) ; Relation :: macro ( 'simplePaginateFilter' , function ( ) { $ paginator = call_user_func_array ( [ $ this , 'simplePaginate' ] , func_get_args ( ) ) ; $ paginator -> appends ( $ this -> getRelated ( ) -> filtered ) ; return $ paginator ; } ) ; } }
|
Register paginate and simplePaginate macros on relations BelongsToMany overrides the QueryBuilder s paginate to append the pivot .
|
6,715
|
public function scopeFilter ( $ query , array $ input = [ ] , $ filter = null ) { if ( $ filter === null ) { $ filter = $ this -> getModelFilterClass ( ) ; } $ modelFilter = new $ filter ( $ query , $ input ) ; $ this -> filtered = $ modelFilter -> input ( ) ; return $ modelFilter -> handle ( ) ; }
|
Creates local scope to run the filter .
|
6,716
|
public function provideFilter ( $ filter = null ) { if ( $ filter === null ) { $ filter = config ( 'eloquentfilter.namespace' , 'App\\ModelFilters\\' ) . class_basename ( $ this ) . 'Filter' ; } return $ filter ; }
|
Returns ModelFilter class to be instantiated .
|
6,717
|
public function total ( ) : array { $ stats = $ this -> generate ( ) ; return [ 'Total' , $ stats -> sum ( 'number_of_classes' ) , $ stats -> sum ( 'methods' ) , round ( $ stats -> avg ( 'methods_per_class' ) , 2 ) , $ stats -> sum ( 'lines' ) , $ stats -> sum ( 'loc' ) , round ( $ stats -> avg ( 'loc_per_method' ) , 2 ) , ] ; }
|
Create Total Row for current Project Statistics .
|
6,718
|
private function generate ( ) : Collection { if ( ! $ this -> cache ) { $ this -> cache = $ this -> components -> map ( function ( $ classes , $ name ) { return ( new ComponentStatistics ( $ name , $ classes ) ) -> toArray ( ) ; } ) -> sortBy ( function ( $ component , $ _ ) { return Str :: contains ( $ component [ 'component' ] , 'Test' ) ? 1 : $ component [ 'component' ] ; } ) ; } return $ this -> cache ; }
|
Generate Project Statistics .
|
6,719
|
public function getLines ( ) : int { return $ this -> classes -> map ( function ( $ class ) { return $ class -> getFileName ( ) ; } ) -> pipe ( function ( $ classes ) { return app ( Analyser :: class ) -> countFiles ( $ classes -> all ( ) , false ) [ 'loc' ] ; } ) ; }
|
Return the total number of lines .
|
6,720
|
public function getLinesOfCode ( ) : float { return $ this -> classes -> map ( function ( $ class ) { return $ class -> getFileName ( ) ; } ) -> pipe ( function ( $ classes ) { return app ( Analyser :: class ) -> countFiles ( $ classes -> all ( ) , false ) [ 'lloc' ] ; } ) ; }
|
Return the total number of lines of code .
|
6,721
|
public function toArray ( ) : array { return [ 'component' => $ this -> name , 'number_of_classes' => $ this -> getNumberOfClasses ( ) , 'methods' => $ this -> getNumberOfMethods ( ) , 'methods_per_class' => $ this -> getNumberOfMethodsPerClass ( ) , 'lines' => $ this -> getLines ( ) , 'loc' => $ this -> getLinesOfCode ( ) , 'loc_per_method' => $ this -> getLinesOfCodePerMethod ( ) , ] ; }
|
Generate Statistics Array for the given Component .
|
6,722
|
public function get ( ) { return $ this -> findAndLoadClasses ( ) -> map ( function ( $ class ) { return new ReflectionClass ( $ class ) ; } ) -> reject ( function ( $ class ) { return $ this -> rejectionStrategy -> shouldClassBeRejected ( $ class ) ; } ) -> reject ( function ( $ class ) { foreach ( config ( 'stats.ignored_namespaces' , [ ] ) as $ namespace ) { if ( Str :: startsWith ( $ class -> getNamespaceName ( ) , $ namespace ) ) { return true ; } } return false ; } ) -> groupBy ( function ( $ class ) { return ( new Classifier ) -> classify ( $ class ) ; } ) ; }
|
Scan the Project for PHP Classes turn them into ReflectionClasses reject unwanted Classes and sort them into Components .
|
6,723
|
protected function findFilesInProjectPath ( ) : Collection { $ excludes = collect ( config ( 'stats.exclude' , [ ] ) ) ; $ files = ( new Finder ) -> files ( ) -> in ( config ( 'stats.paths' , [ ] ) ) -> name ( '*.php' ) ; return collect ( $ files ) -> reject ( function ( $ file ) use ( $ excludes ) { return $ this -> isExcluded ( $ file , $ excludes ) ; } ) ; }
|
Find PHP Files which should be analyzed .
|
6,724
|
protected function isExcluded ( SplFileInfo $ file , Collection $ excludes ) { return $ excludes -> contains ( function ( $ exclude ) use ( $ file ) { return Str :: startsWith ( $ file -> getPathname ( ) , $ exclude ) ; } ) ; }
|
Determine if a file has been defined in the exclude configuration .
|
6,725
|
public function classify ( ReflectionClass $ class ) { $ mergedClassifiers = array_merge ( self :: DEFAULT_CLASSIFIER , config ( 'stats.custom_component_classifier' , [ ] ) ) ; foreach ( $ mergedClassifiers as $ classifier ) { $ c = new $ classifier ( ) ; if ( ! $ this -> implementsContract ( $ classifier ) ) { throw new Exception ( "Classifier {$classifier} does not implement " . ClassifierContract :: class . '.' ) ; } try { $ satisfied = $ c -> satisfies ( $ class ) ; } catch ( Exception $ e ) { $ satisfied = false ; } if ( $ satisfied ) { return $ c -> getName ( ) ; } } return 'Other' ; }
|
Classify a given Class by an available Classifier Strategy .
|
6,726
|
public function getDefinedMethods ( ) : Collection { return collect ( $ this -> getMethods ( ) ) -> filter ( function ( $ method ) { return $ method -> getFileName ( ) == $ this -> getFileName ( ) ; } ) ; }
|
Return a collection of methods defined on the given class . This ignores methods defined in parent class traits etc .
|
6,727
|
public function generate ( int $ amount = 1 ) : array { $ codes = [ ] ; for ( $ i = 1 ; $ i <= $ amount ; $ i ++ ) { $ codes [ ] = $ this -> getUniqueVoucher ( ) ; } return $ codes ; }
|
Generate the specified amount of codes and return an array with all the generated codes .
|
6,728
|
private function getMetadataForRegion ( $ regionCode ) { $ countryCallingCode = $ this -> phoneUtil -> getCountryCodeForRegion ( $ regionCode ) ; $ mainCountry = $ this -> phoneUtil -> getRegionCodeForCountryCode ( $ countryCallingCode ) ; $ metadata = $ this -> phoneUtil -> getMetadataForRegion ( $ mainCountry ) ; if ( $ metadata !== null ) { return $ metadata ; } return self :: $ emptyMetadata ; }
|
The metadata needed by this class is the same for all regions sharing the same country calling code . Therefore we return the metadata for the main region for this country calling code .
|
6,729
|
private function maybeCreateNewTemplate ( ) { foreach ( $ this -> possibleFormats as $ key => $ numberFormat ) { $ pattern = $ numberFormat -> getPattern ( ) ; if ( $ this -> currentFormattingPattern == $ pattern ) { return false ; } if ( $ this -> createFormattingTemplate ( $ numberFormat ) ) { $ this -> currentFormattingPattern = $ pattern ; $ nationalPrefixSeparatorsMatcher = new Matcher ( self :: $ nationalPrefixSeparatorsPattern , $ numberFormat -> getNationalPrefixFormattingRule ( ) ) ; $ this -> shouldAddSpaceAfterNationalPrefix = $ nationalPrefixSeparatorsMatcher -> find ( ) ; $ this -> lastMatchPosition = 0 ; return true ; } unset ( $ this -> possibleFormats [ $ key ] ) ; } $ this -> ableToFormat = false ; return false ; }
|
Returns true if a new template is created as opposed to reusing the existing template .
|
6,730
|
private function getFormattingTemplate ( $ numberPattern , $ numberFormat ) { $ longestPhoneNumber = '999999999999999' ; $ m = new Matcher ( $ numberPattern , $ longestPhoneNumber ) ; $ m -> find ( ) ; $ aPhoneNumber = $ m -> group ( ) ; if ( mb_strlen ( $ aPhoneNumber ) < mb_strlen ( $ this -> nationalNumber ) ) { return '' ; } $ template = preg_replace ( '/' . $ numberPattern . '/' . PhoneNumberUtil :: REGEX_FLAGS , $ numberFormat , $ aPhoneNumber ) ; $ template = preg_replace ( '/9/' , self :: $ digitPattern , $ template ) ; return $ template ; }
|
Gets a formatting template which can be used to efficiently format a partial number where digits are added one by one .
|
6,731
|
public function clear ( ) { $ this -> currentOutput = '' ; $ this -> accruedInput = '' ; $ this -> accruedInputWithoutFormatting = '' ; $ this -> formattingTemplate = '' ; $ this -> lastMatchPosition = 0 ; $ this -> currentFormattingPattern = '' ; $ this -> prefixBeforeNationalNumber = '' ; $ this -> extractedNationalPrefix = '' ; $ this -> nationalNumber = '' ; $ this -> ableToFormat = true ; $ this -> inputHasFormatting = false ; $ this -> positionToRemember = 0 ; $ this -> originalPosition = 0 ; $ this -> isCompleteNumber = false ; $ this -> isExpectingCountryCallingCode = false ; $ this -> possibleFormats = array ( ) ; $ this -> shouldAddSpaceAfterNationalPrefix = false ; if ( $ this -> currentMetadata !== $ this -> defaultMetadata ) { $ this -> currentMetadata = $ this -> getMetadataForRegion ( $ this -> defaultCountry ) ; } }
|
Clears the internal state of the formatter so it can be reused .
|
6,732
|
public function inputDigit ( $ nextChar ) { $ this -> currentOutput = $ this -> inputDigitWithOptionToRememberPosition ( $ nextChar , false ) ; return $ this -> currentOutput ; }
|
Formats a phone number on - the - fly as each digit is entered .
|
6,733
|
private function ableToExtractLongerNdd ( ) { if ( mb_strlen ( $ this -> extractedNationalPrefix ) > 0 ) { $ this -> nationalNumber = $ this -> extractedNationalPrefix . $ this -> nationalNumber ; $ indexOfPreviousNdd = mb_strrpos ( $ this -> prefixBeforeNationalNumber , $ this -> extractedNationalPrefix ) ; $ this -> prefixBeforeNationalNumber = mb_substr ( str_pad ( $ this -> prefixBeforeNationalNumber , $ indexOfPreviousNdd ) , 0 , $ indexOfPreviousNdd ) ; } return ( $ this -> extractedNationalPrefix !== $ this -> removeNationalPrefixFromNationalNumber ( ) ) ; }
|
Some national prefixes are a substring of others . If extracting the shorter NDD doesn t result in a number we can format we try to see if we can extract a longer version here .
|
6,734
|
public function attemptToFormatAccruedDigits ( ) { foreach ( $ this -> possibleFormats as $ numberFormat ) { $ m = new Matcher ( $ numberFormat -> getPattern ( ) , $ this -> nationalNumber ) ; if ( $ m -> matches ( ) ) { $ nationalPrefixSeparatorsMatcher = new Matcher ( self :: $ nationalPrefixSeparatorsPattern , $ numberFormat -> getNationalPrefixFormattingRule ( ) ) ; $ this -> shouldAddSpaceAfterNationalPrefix = $ nationalPrefixSeparatorsMatcher -> find ( ) ; $ formattedNumber = $ m -> replaceAll ( $ numberFormat -> getFormat ( ) ) ; return $ this -> appendNationalNumber ( $ formattedNumber ) ; } } return '' ; }
|
Checks to see if there is an exact pattern match for these digits . If so we should use this instead of any other formatting template whose leadingDigitsPattern also matches the input .
|
6,735
|
private function attemptToChooseFormattingPattern ( ) { if ( mb_strlen ( $ this -> nationalNumber ) >= self :: $ minLeadingDigitsLength ) { $ this -> getAvailableFormats ( $ this -> nationalNumber ) ; $ formattedNumber = $ this -> attemptToFormatAccruedDigits ( ) ; if ( mb_strlen ( $ formattedNumber ) > 0 ) { return $ formattedNumber ; } return $ this -> maybeCreateNewTemplate ( ) ? $ this -> inputAccruedNationalNumber ( ) : $ this -> accruedInput ; } return $ this -> appendNationalNumber ( $ this -> nationalNumber ) ; }
|
Attempts to set the formatting template and returns a string which contains the formatted version of the digits entered so far .
|
6,736
|
private function inputAccruedNationalNumber ( ) { $ lengthOfNationalNumber = mb_strlen ( $ this -> nationalNumber ) ; if ( $ lengthOfNationalNumber > 0 ) { $ tempNationalNumber = '' ; for ( $ i = 0 ; $ i < $ lengthOfNationalNumber ; $ i ++ ) { $ tempNationalNumber = $ this -> inputDigitHelper ( mb_substr ( $ this -> nationalNumber , $ i , 1 ) ) ; } return $ this -> ableToFormat ? $ this -> appendNationalNumber ( $ tempNationalNumber ) : $ this -> accruedInput ; } return $ this -> prefixBeforeNationalNumber ; }
|
Invokes inputDigitHelper on each digit of the national number accrued and returns a formatted string in the end
|
6,737
|
private function isNanpaNumberWithNationalPrefix ( ) { return ( $ this -> currentMetadata -> getCountryCode ( ) == 1 ) && ( mb_substr ( $ this -> nationalNumber , 0 , 1 ) == '1' ) && ( mb_substr ( $ this -> nationalNumber , 1 , 1 ) != '0' ) && ( mb_substr ( $ this -> nationalNumber , 1 , 1 ) != '1' ) ; }
|
Returns true if the current country is a NANPA country and the national number beings with the national prefix
|
6,738
|
private function removeNationalPrefixFromNationalNumber ( ) { $ startOfNationalNumber = 0 ; if ( $ this -> isNanpaNumberWithNationalPrefix ( ) ) { $ startOfNationalNumber = 1 ; $ this -> prefixBeforeNationalNumber .= '1' . self :: $ seperatorBeforeNationalNumber ; $ this -> isCompleteNumber = true ; } elseif ( $ this -> currentMetadata -> hasNationalPrefixForParsing ( ) ) { $ m = new Matcher ( $ this -> currentMetadata -> getNationalPrefixForParsing ( ) , $ this -> nationalNumber ) ; if ( $ m -> lookingAt ( ) && $ m -> end ( ) > 0 ) { $ this -> isCompleteNumber = true ; $ startOfNationalNumber = $ m -> end ( ) ; $ this -> prefixBeforeNationalNumber .= mb_substr ( $ this -> nationalNumber , 0 , $ startOfNationalNumber ) ; } } $ nationalPrefix = mb_substr ( $ this -> nationalNumber , 0 , $ startOfNationalNumber ) ; $ this -> nationalNumber = mb_substr ( $ this -> nationalNumber , $ startOfNationalNumber ) ; return $ nationalPrefix ; }
|
Returns the national prefix extracted or an empty string if it is not present .
|
6,739
|
protected static function normalizeHelper ( $ number , array $ normalizationReplacements , $ removeNonMatches ) { $ normalizedNumber = '' ; $ strLength = mb_strlen ( $ number , 'UTF-8' ) ; for ( $ i = 0 ; $ i < $ strLength ; $ i ++ ) { $ character = mb_substr ( $ number , $ i , 1 , 'UTF-8' ) ; if ( isset ( $ normalizationReplacements [ mb_strtoupper ( $ character , 'UTF-8' ) ] ) ) { $ normalizedNumber .= $ normalizationReplacements [ mb_strtoupper ( $ character , 'UTF-8' ) ] ; } elseif ( ! $ removeNonMatches ) { $ normalizedNumber .= $ character ; } } return $ normalizedNumber ; }
|
Normalizes a string of characters representing a phone number by replacing all characters found in the accompanying map with the values therein and stripping all other characters if removeNonMatches is true .
|
6,740
|
public static function formattingRuleHasFirstGroupOnly ( $ nationalPrefixFormattingRule ) { $ firstGroupOnlyPrefixPatternMatcher = new Matcher ( static :: FIRST_GROUP_ONLY_PREFIX_PATTERN , $ nationalPrefixFormattingRule ) ; return mb_strlen ( $ nationalPrefixFormattingRule ) === 0 || $ firstGroupOnlyPrefixPatternMatcher -> matches ( ) ; }
|
Helper function to check if the national prefix formatting rule has the first group only i . e . does not start with the national prefix .
|
6,741
|
private function getSupportedTypesForMetadata ( PhoneMetadata $ metadata ) { $ types = array ( ) ; foreach ( array_keys ( PhoneNumberType :: values ( ) ) as $ type ) { if ( $ type === PhoneNumberType :: FIXED_LINE_OR_MOBILE || $ type === PhoneNumberType :: UNKNOWN ) { continue ; } if ( self :: descHasData ( $ this -> getNumberDescByType ( $ metadata , $ type ) ) ) { $ types [ ] = $ type ; } } return $ types ; }
|
Returns the types we have metadata for based on the PhoneMetadata object passed in
|
6,742
|
public function getNationalSignificantNumber ( PhoneNumber $ number ) { $ nationalNumber = '' ; if ( $ number -> isItalianLeadingZero ( ) && $ number -> getNumberOfLeadingZeros ( ) > 0 ) { $ zeros = str_repeat ( '0' , $ number -> getNumberOfLeadingZeros ( ) ) ; $ nationalNumber .= $ zeros ; } $ nationalNumber .= $ number -> getNationalNumber ( ) ; return $ nationalNumber ; }
|
Gets the national significant number of the a phone number . Note a national significant number doesn t contain a national prefix or any formatting .
|
6,743
|
public function getNumberType ( PhoneNumber $ number ) { $ regionCode = $ this -> getRegionCodeForNumber ( $ number ) ; $ metadata = $ this -> getMetadataForRegionOrCallingCode ( $ number -> getCountryCode ( ) , $ regionCode ) ; if ( $ metadata === null ) { return PhoneNumberType :: UNKNOWN ; } $ nationalSignificantNumber = $ this -> getNationalSignificantNumber ( $ number ) ; return $ this -> getNumberTypeHelper ( $ nationalSignificantNumber , $ metadata ) ; }
|
Gets the type of a valid phone number .
|
6,744
|
public function format ( PhoneNumber $ number , $ numberFormat ) { if ( $ number -> getNationalNumber ( ) == 0 && $ number -> hasRawInput ( ) ) { $ rawInput = $ number -> getRawInput ( ) ; if ( mb_strlen ( $ rawInput ) > 0 ) { return $ rawInput ; } } $ formattedNumber = '' ; $ countryCallingCode = $ number -> getCountryCode ( ) ; $ nationalSignificantNumber = $ this -> getNationalSignificantNumber ( $ number ) ; if ( $ numberFormat == PhoneNumberFormat :: E164 ) { $ formattedNumber .= $ nationalSignificantNumber ; $ this -> prefixNumberWithCountryCallingCode ( $ countryCallingCode , PhoneNumberFormat :: E164 , $ formattedNumber ) ; return $ formattedNumber ; } if ( ! $ this -> hasValidCountryCallingCode ( $ countryCallingCode ) ) { $ formattedNumber .= $ nationalSignificantNumber ; return $ formattedNumber ; } $ regionCode = $ this -> getRegionCodeForCountryCode ( $ countryCallingCode ) ; $ metadata = $ this -> getMetadataForRegionOrCallingCode ( $ countryCallingCode , $ regionCode ) ; $ formattedNumber .= $ this -> formatNsn ( $ nationalSignificantNumber , $ metadata , $ numberFormat ) ; $ this -> maybeAppendFormattedExtension ( $ number , $ metadata , $ numberFormat , $ formattedNumber ) ; $ this -> prefixNumberWithCountryCallingCode ( $ countryCallingCode , $ numberFormat , $ formattedNumber ) ; return $ formattedNumber ; }
|
Formats a phone number in the specified format using default rules . Note that this does not promise to produce a phone number that the user can dial from where they are - although we do format in either national or international format depending on what the client asks for we do not currently support a more abbreviated format such as for users in the same area who could potentially dial the number without area code . Note that if the phone number has a country calling code of 0 or an otherwise invalid country calling code we cannot work out which formatting rules to apply so we return the national significant number with no formatting applied .
|
6,745
|
protected function prefixNumberWithCountryCallingCode ( $ countryCallingCode , $ numberFormat , & $ formattedNumber ) { switch ( $ numberFormat ) { case PhoneNumberFormat :: E164 : $ formattedNumber = static :: PLUS_SIGN . $ countryCallingCode . $ formattedNumber ; return ; case PhoneNumberFormat :: INTERNATIONAL : $ formattedNumber = static :: PLUS_SIGN . $ countryCallingCode . ' ' . $ formattedNumber ; return ; case PhoneNumberFormat :: RFC3966 : $ formattedNumber = static :: RFC3966_PREFIX . static :: PLUS_SIGN . $ countryCallingCode . '-' . $ formattedNumber ; return ; case PhoneNumberFormat :: NATIONAL : default : return ; } }
|
A helper function that is used by format and formatByPattern .
|
6,746
|
public function formatNsnUsingPattern ( $ nationalNumber , NumberFormat $ formattingPattern , $ numberFormat , $ carrierCode = null ) { $ numberFormatRule = $ formattingPattern -> getFormat ( ) ; $ m = new Matcher ( $ formattingPattern -> getPattern ( ) , $ nationalNumber ) ; if ( $ numberFormat === PhoneNumberFormat :: NATIONAL && $ carrierCode !== null && mb_strlen ( $ carrierCode ) > 0 && mb_strlen ( $ formattingPattern -> getDomesticCarrierCodeFormattingRule ( ) ) > 0 ) { $ carrierCodeFormattingRule = $ formattingPattern -> getDomesticCarrierCodeFormattingRule ( ) ; $ carrierCodeFormattingRule = str_replace ( static :: CC_STRING , $ carrierCode , $ carrierCodeFormattingRule ) ; $ firstGroupMatcher = new Matcher ( static :: FIRST_GROUP_PATTERN , $ numberFormatRule ) ; $ numberFormatRule = $ firstGroupMatcher -> replaceFirst ( $ carrierCodeFormattingRule ) ; $ formattedNationalNumber = $ m -> replaceAll ( $ numberFormatRule ) ; } else { $ nationalPrefixFormattingRule = $ formattingPattern -> getNationalPrefixFormattingRule ( ) ; if ( $ numberFormat == PhoneNumberFormat :: NATIONAL && $ nationalPrefixFormattingRule !== null && mb_strlen ( $ nationalPrefixFormattingRule ) > 0 ) { $ firstGroupMatcher = new Matcher ( static :: FIRST_GROUP_PATTERN , $ numberFormatRule ) ; $ formattedNationalNumber = $ m -> replaceAll ( $ firstGroupMatcher -> replaceFirst ( $ nationalPrefixFormattingRule ) ) ; } else { $ formattedNationalNumber = $ m -> replaceAll ( $ numberFormatRule ) ; } } if ( $ numberFormat == PhoneNumberFormat :: RFC3966 ) { $ matcher = new Matcher ( static :: $ SEPARATOR_PATTERN , $ formattedNationalNumber ) ; if ( $ matcher -> lookingAt ( ) ) { $ formattedNationalNumber = $ matcher -> replaceFirst ( '' ) ; } $ formattedNationalNumber = $ matcher -> reset ( $ formattedNationalNumber ) -> replaceAll ( '-' ) ; } return $ formattedNationalNumber ; }
|
Note that carrierCode is optional - if null or an empty string no carrier code replacement will take place .
|
6,747
|
protected function maybeAppendFormattedExtension ( PhoneNumber $ number , $ metadata , $ numberFormat , & $ formattedNumber ) { if ( $ number -> hasExtension ( ) && mb_strlen ( $ number -> getExtension ( ) ) > 0 ) { if ( $ numberFormat === PhoneNumberFormat :: RFC3966 ) { $ formattedNumber .= static :: RFC3966_EXTN_PREFIX . $ number -> getExtension ( ) ; } elseif ( ! empty ( $ metadata ) && $ metadata -> hasPreferredExtnPrefix ( ) ) { $ formattedNumber .= $ metadata -> getPreferredExtnPrefix ( ) . $ number -> getExtension ( ) ; } else { $ formattedNumber .= static :: DEFAULT_EXTN_PREFIX . $ number -> getExtension ( ) ; } } }
|
Appends the formatted extension of a phone number to formattedNumber if the phone number had an extension specified .
|
6,748
|
public static function getCountryMobileToken ( $ countryCallingCode ) { if ( count ( static :: $ MOBILE_TOKEN_MAPPINGS ) === 0 ) { static :: initMobileTokenMappings ( ) ; } if ( array_key_exists ( $ countryCallingCode , static :: $ MOBILE_TOKEN_MAPPINGS ) ) { return static :: $ MOBILE_TOKEN_MAPPINGS [ $ countryCallingCode ] ; } return '' ; }
|
Returns the mobile token for the provided country calling code if it has one otherwise returns an empty string . A mobile token is a number inserted before the area code when dialing a mobile number from that country from abroad .
|
6,749
|
public static function isViablePhoneNumber ( $ number ) { if ( static :: $ VALID_PHONE_NUMBER_PATTERN === null ) { static :: initValidPhoneNumberPatterns ( ) ; } if ( mb_strlen ( $ number ) < static :: MIN_LENGTH_FOR_NSN ) { return false ; } $ validPhoneNumberPattern = static :: getValidPhoneNumberPattern ( ) ; $ m = preg_match ( $ validPhoneNumberPattern , $ number ) ; return $ m > 0 ; }
|
Checks to see if the string of characters could possibly be a phone number at all . At the moment checks to see that the string begins with at least 2 digits ignoring any punctuation commonly found in phone numbers . This method does not require the number to be normalized in advance - but does assume that leading non - number symbols have been removed such as by the method extractPossibleNumber .
|
6,750
|
public static function setItalianLeadingZerosForPhoneNumber ( $ nationalNumber , PhoneNumber $ phoneNumber ) { if ( strlen ( $ nationalNumber ) > 1 && substr ( $ nationalNumber , 0 , 1 ) == '0' ) { $ phoneNumber -> setItalianLeadingZero ( true ) ; $ numberOfLeadingZeros = 1 ; while ( $ numberOfLeadingZeros < ( strlen ( $ nationalNumber ) - 1 ) && substr ( $ nationalNumber , $ numberOfLeadingZeros , 1 ) == '0' ) { $ numberOfLeadingZeros ++ ; } if ( $ numberOfLeadingZeros != 1 ) { $ phoneNumber -> setNumberOfLeadingZeros ( $ numberOfLeadingZeros ) ; } } }
|
A helper function to set the values related to leading zeros in a PhoneNumber .
|
6,751
|
protected function buildNationalNumberForParsing ( $ numberToParse , & $ nationalNumber ) { $ indexOfPhoneContext = strpos ( $ numberToParse , static :: RFC3966_PHONE_CONTEXT ) ; if ( $ indexOfPhoneContext !== false ) { $ phoneContextStart = $ indexOfPhoneContext + mb_strlen ( static :: RFC3966_PHONE_CONTEXT ) ; if ( $ phoneContextStart < ( strlen ( $ numberToParse ) - 1 ) && substr ( $ numberToParse , $ phoneContextStart , 1 ) == static :: PLUS_SIGN ) { $ phoneContextEnd = strpos ( $ numberToParse , ';' , $ phoneContextStart ) ; if ( $ phoneContextEnd > 0 ) { $ nationalNumber .= substr ( $ numberToParse , $ phoneContextStart , $ phoneContextEnd - $ phoneContextStart ) ; } else { $ nationalNumber .= substr ( $ numberToParse , $ phoneContextStart ) ; } } $ indexOfRfc3966Prefix = strpos ( $ numberToParse , static :: RFC3966_PREFIX ) ; $ indexOfNationalNumber = ( $ indexOfRfc3966Prefix !== false ) ? $ indexOfRfc3966Prefix + strlen ( static :: RFC3966_PREFIX ) : 0 ; $ nationalNumber .= substr ( $ numberToParse , $ indexOfNationalNumber , $ indexOfPhoneContext - $ indexOfNationalNumber ) ; } else { $ nationalNumber .= static :: extractPossibleNumber ( $ numberToParse ) ; } $ indexOfIsdn = strpos ( $ nationalNumber , static :: RFC3966_ISDN_SUBADDRESS ) ; if ( $ indexOfIsdn > 0 ) { $ nationalNumber = substr ( $ nationalNumber , 0 , $ indexOfIsdn ) ; } }
|
Converts numberToParse to a form that we can parse and write it to nationalNumber if it is written in RFC3966 ; otherwise extract a possible number out of it and write to nationalNumber .
|
6,752
|
protected function checkRegionForParsing ( $ numberToParse , $ defaultRegion ) { if ( ! $ this -> isValidRegionCode ( $ defaultRegion ) ) { $ plusCharsPatternMatcher = new Matcher ( static :: $ PLUS_CHARS_PATTERN , $ numberToParse ) ; if ( $ numberToParse === null || mb_strlen ( $ numberToParse ) == 0 || ! $ plusCharsPatternMatcher -> lookingAt ( ) ) { return false ; } } return true ; }
|
Checks to see that the region code used is valid or if it is not valid that the number to parse starts with a + symbol so that we can attempt to infer the region from the number . Returns false if it cannot use the region provided and the region cannot be inferred .
|
6,753
|
protected function parsePrefixAsIdd ( $ iddPattern , & $ number ) { $ m = new Matcher ( $ iddPattern , $ number ) ; if ( $ m -> lookingAt ( ) ) { $ matchEnd = $ m -> end ( ) ; $ digitMatcher = new Matcher ( static :: $ CAPTURING_DIGIT_PATTERN , substr ( $ number , $ matchEnd ) ) ; if ( $ digitMatcher -> find ( ) ) { $ normalizedGroup = static :: normalizeDigitsOnly ( $ digitMatcher -> group ( 1 ) ) ; if ( $ normalizedGroup == '0' ) { return false ; } } $ number = substr ( $ number , $ matchEnd ) ; return true ; } return false ; }
|
Strips the IDD from the start of the number if present . Helper function used by maybeStripInternationalPrefixAndNormalize .
|
6,754
|
public function extractCountryCode ( $ fullNumber , & $ nationalNumber ) { if ( ( mb_strlen ( $ fullNumber ) == 0 ) || ( $ fullNumber [ 0 ] == '0' ) ) { return 0 ; } $ numberLength = mb_strlen ( $ fullNumber ) ; for ( $ i = 1 ; $ i <= static :: MAX_LENGTH_COUNTRY_CODE && $ i <= $ numberLength ; $ i ++ ) { $ potentialCountryCode = ( int ) substr ( $ fullNumber , 0 , $ i ) ; if ( isset ( $ this -> countryCallingCodeToRegionCodeMap [ $ potentialCountryCode ] ) ) { $ nationalNumber .= substr ( $ fullNumber , $ i ) ; return $ potentialCountryCode ; } } return 0 ; }
|
Extracts country calling code from fullNumber returns it and places the remaining number in nationalNumber . It assumes that the leading plus sign or IDD has already been removed . Returns 0 if fullNumber doesn t start with a valid country calling code and leaves nationalNumber unmodified .
|
6,755
|
public function getRegionCodesForCountryCode ( $ countryCallingCode ) { $ regionCodes = isset ( $ this -> countryCallingCodeToRegionCodeMap [ $ countryCallingCode ] ) ? $ this -> countryCallingCodeToRegionCodeMap [ $ countryCallingCode ] : null ; return $ regionCodes === null ? array ( ) : $ regionCodes ; }
|
Returns a list with the 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 .
|
6,756
|
protected function getCountryCodeForValidRegion ( $ regionCode ) { $ metadata = $ this -> getMetadataForRegion ( $ regionCode ) ; if ( $ metadata === null ) { throw new \ InvalidArgumentException ( 'Invalid region code: ' . $ regionCode ) ; } return $ metadata -> getCountryCode ( ) ; }
|
Returns the country calling code for a specific region . For example this would be 1 for the United States and 64 for New Zealand . Assumes the region is already valid .
|
6,757
|
public function formatOutOfCountryKeepingAlphaChars ( PhoneNumber $ number , $ regionCallingFrom ) { $ rawInput = $ number -> getRawInput ( ) ; if ( mb_strlen ( $ rawInput ) == 0 ) { return $ this -> formatOutOfCountryCallingNumber ( $ number , $ regionCallingFrom ) ; } $ countryCode = $ number -> getCountryCode ( ) ; if ( ! $ this -> hasValidCountryCallingCode ( $ countryCode ) ) { return $ rawInput ; } $ rawInput = self :: normalizeHelper ( $ rawInput , static :: $ ALL_PLUS_NUMBER_GROUPING_SYMBOLS , true ) ; $ nationalNumber = $ this -> getNationalSignificantNumber ( $ number ) ; if ( mb_strlen ( $ nationalNumber ) > 3 ) { $ firstNationalNumberDigit = strpos ( $ rawInput , substr ( $ nationalNumber , 0 , 3 ) ) ; if ( $ firstNationalNumberDigit !== false ) { $ rawInput = substr ( $ rawInput , $ firstNationalNumberDigit ) ; } } $ metadataForRegionCallingFrom = $ this -> getMetadataForRegion ( $ regionCallingFrom ) ; if ( $ countryCode == static :: NANPA_COUNTRY_CODE ) { if ( $ this -> isNANPACountry ( $ regionCallingFrom ) ) { return $ countryCode . ' ' . $ rawInput ; } } elseif ( $ metadataForRegionCallingFrom !== null && $ countryCode == $ this -> getCountryCodeForValidRegion ( $ regionCallingFrom ) ) { $ formattingPattern = $ this -> chooseFormattingPatternForNumber ( $ metadataForRegionCallingFrom -> numberFormats ( ) , $ nationalNumber ) ; if ( $ formattingPattern === null ) { return $ rawInput ; } $ newFormat = new NumberFormat ( ) ; $ newFormat -> mergeFrom ( $ formattingPattern ) ; $ newFormat -> setPattern ( "(\\d+)(.*)" ) ; $ newFormat -> setFormat ( '$1$2' ) ; return $ this -> formatNsnUsingPattern ( $ rawInput , $ newFormat , PhoneNumberFormat :: NATIONAL ) ; } $ internationalPrefixForFormatting = '' ; if ( $ metadataForRegionCallingFrom !== null ) { $ internationalPrefix = $ metadataForRegionCallingFrom -> getInternationalPrefix ( ) ; $ uniqueInternationalPrefixMatcher = new Matcher ( static :: SINGLE_INTERNATIONAL_PREFIX , $ internationalPrefix ) ; $ internationalPrefixForFormatting = $ uniqueInternationalPrefixMatcher -> matches ( ) ? $ internationalPrefix : $ metadataForRegionCallingFrom -> getPreferredInternationalPrefix ( ) ; } $ formattedNumber = $ rawInput ; $ regionCode = $ this -> getRegionCodeForCountryCode ( $ countryCode ) ; $ metadataForRegion = $ this -> getMetadataForRegionOrCallingCode ( $ countryCode , $ regionCode ) ; $ this -> maybeAppendFormattedExtension ( $ number , $ metadataForRegion , PhoneNumberFormat :: INTERNATIONAL , $ formattedNumber ) ; if ( mb_strlen ( $ internationalPrefixForFormatting ) > 0 ) { $ formattedNumber = $ internationalPrefixForFormatting . ' ' . $ countryCode . ' ' . $ formattedNumber ; } else { $ this -> prefixNumberWithCountryCallingCode ( $ countryCode , PhoneNumberFormat :: INTERNATIONAL , $ formattedNumber ) ; } return $ formattedNumber ; }
|
Formats a phone number for out - of - country dialing purposes .
|
6,758
|
public function formatOutOfCountryCallingNumber ( PhoneNumber $ number , $ regionCallingFrom ) { if ( ! $ this -> isValidRegionCode ( $ regionCallingFrom ) ) { return $ this -> format ( $ number , PhoneNumberFormat :: INTERNATIONAL ) ; } $ countryCallingCode = $ number -> getCountryCode ( ) ; $ nationalSignificantNumber = $ this -> getNationalSignificantNumber ( $ number ) ; if ( ! $ this -> hasValidCountryCallingCode ( $ countryCallingCode ) ) { return $ nationalSignificantNumber ; } if ( $ countryCallingCode == static :: NANPA_COUNTRY_CODE ) { if ( $ this -> isNANPACountry ( $ regionCallingFrom ) ) { return $ countryCallingCode . ' ' . $ this -> format ( $ number , PhoneNumberFormat :: NATIONAL ) ; } } elseif ( $ countryCallingCode == $ this -> getCountryCodeForValidRegion ( $ regionCallingFrom ) ) { return $ this -> format ( $ number , PhoneNumberFormat :: NATIONAL ) ; } $ metadataForRegionCallingFrom = $ this -> getMetadataForRegion ( $ regionCallingFrom ) ; $ internationalPrefix = $ metadataForRegionCallingFrom -> getInternationalPrefix ( ) ; $ internationalPrefixForFormatting = '' ; $ uniqueInternationalPrefixMatcher = new Matcher ( static :: SINGLE_INTERNATIONAL_PREFIX , $ internationalPrefix ) ; if ( $ uniqueInternationalPrefixMatcher -> matches ( ) ) { $ internationalPrefixForFormatting = $ internationalPrefix ; } elseif ( $ metadataForRegionCallingFrom -> hasPreferredInternationalPrefix ( ) ) { $ internationalPrefixForFormatting = $ metadataForRegionCallingFrom -> getPreferredInternationalPrefix ( ) ; } $ regionCode = $ this -> getRegionCodeForCountryCode ( $ countryCallingCode ) ; $ metadataForRegion = $ this -> getMetadataForRegionOrCallingCode ( $ countryCallingCode , $ regionCode ) ; $ formattedNationalNumber = $ this -> formatNsn ( $ nationalSignificantNumber , $ metadataForRegion , PhoneNumberFormat :: INTERNATIONAL ) ; $ formattedNumber = $ formattedNationalNumber ; $ this -> maybeAppendFormattedExtension ( $ number , $ metadataForRegion , PhoneNumberFormat :: INTERNATIONAL , $ formattedNumber ) ; if ( mb_strlen ( $ internationalPrefixForFormatting ) > 0 ) { $ formattedNumber = $ internationalPrefixForFormatting . ' ' . $ countryCallingCode . ' ' . $ formattedNumber ; } else { $ this -> prefixNumberWithCountryCallingCode ( $ countryCallingCode , PhoneNumberFormat :: INTERNATIONAL , $ formattedNumber ) ; } return $ formattedNumber ; }
|
Formats a phone number for out - of - country dialing purposes . If no regionCallingFrom is supplied we format the number in its INTERNATIONAL format . If the country calling code is the same as that of the region where the number is from then NATIONAL formatting will be applied .
|
6,759
|
protected function rawInputContainsNationalPrefix ( $ rawInput , $ nationalPrefix , $ regionCode ) { $ normalizedNationalNumber = static :: normalizeDigitsOnly ( $ rawInput ) ; if ( strpos ( $ normalizedNationalNumber , $ nationalPrefix ) === 0 ) { try { return $ this -> isValidNumber ( $ this -> parse ( substr ( $ normalizedNationalNumber , mb_strlen ( $ nationalPrefix ) ) , $ regionCode ) ) ; } catch ( NumberParseException $ e ) { return false ; } } return false ; }
|
Check if rawInput which is assumed to be in the national format has a national prefix . The national prefix is assumed to be in digits - only form .
|
6,760
|
public function formatByPattern ( PhoneNumber $ number , $ numberFormat , array $ userDefinedFormats ) { $ countryCallingCode = $ number -> getCountryCode ( ) ; $ nationalSignificantNumber = $ this -> getNationalSignificantNumber ( $ number ) ; if ( ! $ this -> hasValidCountryCallingCode ( $ countryCallingCode ) ) { return $ nationalSignificantNumber ; } $ regionCode = $ this -> getRegionCodeForCountryCode ( $ countryCallingCode ) ; $ metadata = $ this -> getMetadataForRegionOrCallingCode ( $ countryCallingCode , $ regionCode ) ; $ formattedNumber = '' ; $ formattingPattern = $ this -> chooseFormattingPatternForNumber ( $ userDefinedFormats , $ nationalSignificantNumber ) ; if ( $ formattingPattern === null ) { $ formattedNumber .= $ nationalSignificantNumber ; } else { $ numFormatCopy = new NumberFormat ( ) ; $ numFormatCopy -> mergeFrom ( $ formattingPattern ) ; $ nationalPrefixFormattingRule = $ formattingPattern -> getNationalPrefixFormattingRule ( ) ; if ( mb_strlen ( $ nationalPrefixFormattingRule ) > 0 ) { $ nationalPrefix = $ metadata -> getNationalPrefix ( ) ; if ( mb_strlen ( $ nationalPrefix ) > 0 ) { $ nationalPrefixFormattingRule = str_replace ( array ( static :: NP_STRING , static :: FG_STRING ) , array ( $ nationalPrefix , '$1' ) , $ nationalPrefixFormattingRule ) ; $ numFormatCopy -> setNationalPrefixFormattingRule ( $ nationalPrefixFormattingRule ) ; } else { $ numFormatCopy -> clearNationalPrefixFormattingRule ( ) ; } } $ formattedNumber .= $ this -> formatNsnUsingPattern ( $ nationalSignificantNumber , $ numFormatCopy , $ numberFormat ) ; } $ this -> maybeAppendFormattedExtension ( $ number , $ metadata , $ numberFormat , $ formattedNumber ) ; $ this -> prefixNumberWithCountryCallingCode ( $ countryCallingCode , $ numberFormat , $ formattedNumber ) ; return $ formattedNumber ; }
|
Formats a phone number in the specified format using client - defined formatting rules . Note that if the phone number has a country calling code of zero or an otherwise invalid country calling code we cannot work out things like whether there should be a national prefix applied or how to format extensions so we return the national significant number with no formatting applied .
|
6,761
|
public function getExampleNumberForType ( $ regionCodeOrType , $ type = null ) { if ( $ regionCodeOrType !== null && $ type === null ) { foreach ( $ this -> getSupportedRegions ( ) as $ regionCode ) { $ exampleNumber = $ this -> getExampleNumberForType ( $ regionCode , $ regionCodeOrType ) ; if ( $ exampleNumber !== null ) { return $ exampleNumber ; } } foreach ( $ this -> getSupportedGlobalNetworkCallingCodes ( ) as $ countryCallingCode ) { $ desc = $ this -> getNumberDescByType ( $ this -> getMetadataForNonGeographicalRegion ( $ countryCallingCode ) , $ regionCodeOrType ) ; try { if ( $ desc -> getExampleNumber ( ) != '' ) { return $ this -> parse ( '+' . $ countryCallingCode . $ desc -> getExampleNumber ( ) , static :: UNKNOWN_REGION ) ; } } catch ( NumberParseException $ e ) { } } return null ; } if ( ! $ this -> isValidRegionCode ( $ regionCodeOrType ) ) { return null ; } $ desc = $ this -> getNumberDescByType ( $ this -> getMetadataForRegion ( $ regionCodeOrType ) , $ type ) ; try { if ( $ desc -> hasExampleNumber ( ) ) { return $ this -> parse ( $ desc -> getExampleNumber ( ) , $ regionCodeOrType ) ; } } catch ( NumberParseException $ e ) { } return null ; }
|
Gets a valid number for the specified region and number type .
|
6,762
|
public function getExampleNumberForNonGeoEntity ( $ countryCallingCode ) { $ metadata = $ this -> getMetadataForNonGeographicalRegion ( $ countryCallingCode ) ; if ( $ metadata !== null ) { $ list = array ( $ metadata -> getMobile ( ) , $ metadata -> getTollFree ( ) , $ metadata -> getSharedCost ( ) , $ metadata -> getVoip ( ) , $ metadata -> getVoicemail ( ) , $ metadata -> getUan ( ) , $ metadata -> getPremiumRate ( ) , ) ; foreach ( $ list as $ desc ) { try { if ( $ desc !== null && $ desc -> hasExampleNumber ( ) ) { return $ this -> parse ( '+' . $ countryCallingCode . $ desc -> getExampleNumber ( ) , self :: UNKNOWN_REGION ) ; } } catch ( NumberParseException $ e ) { } } } return null ; }
|
Gets a valid number for the specified country calling code for a non - geographical entity .
|
6,763
|
protected 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 ) ; }
|
Returns true when one national number is the suffix of the other or both are the same .
|
6,764
|
public function isMobileNumberPortableRegion ( $ regionCode ) { $ metadata = $ this -> getMetadataForRegion ( $ regionCode ) ; if ( $ metadata === null ) { return false ; } return $ metadata -> isMobileNumberPortableRegion ( ) ; }
|
Returns true if the supplied region supports mobile number portability . Returns false for invalid unknown or regions that don t support mobile number portability .
|
6,765
|
public function truncateTooLongNumber ( PhoneNumber $ number ) { if ( $ this -> isValidNumber ( $ number ) ) { return true ; } $ numberCopy = new PhoneNumber ( ) ; $ numberCopy -> mergeFrom ( $ number ) ; $ nationalNumber = $ number -> getNationalNumber ( ) ; do { $ nationalNumber = floor ( $ nationalNumber / 10 ) ; $ numberCopy -> setNationalNumber ( $ nationalNumber ) ; if ( $ this -> isPossibleNumberWithReason ( $ numberCopy ) == ValidationResult :: TOO_SHORT || $ nationalNumber == 0 ) { return false ; } } while ( ! $ this -> isValidNumber ( $ numberCopy ) ) ; $ number -> setNationalNumber ( $ nationalNumber ) ; return true ; }
|
Attempts to extract a valid number from a phone number that is too long to be valid and resets the PhoneNumber object passed in to that valid version . If no valid number could be extracted the PhoneNumber object passed in will not be modified .
|
6,766
|
protected function getTimeZonesForGeocodableNumber ( PhoneNumber $ number ) { $ timezones = $ this -> prefixTimeZonesMap -> lookupTimeZonesForNumber ( $ number ) ; return ( count ( $ timezones ) == 0 ) ? $ this -> unknownTimeZoneList : $ timezones ; }
|
Returns a list of time zones to which a geocodable phone number belongs .
|
6,767
|
public function getDescriptionForNumber ( PhoneNumber $ number , $ language , $ script , $ region ) { $ phonePrefix = $ number -> getCountryCode ( ) . PhoneNumberUtil :: getInstance ( ) -> getNationalSignificantNumber ( $ number ) ; $ phonePrefixDescriptions = $ this -> getPhonePrefixDescriptions ( $ phonePrefix , $ language , $ script , $ region ) ; $ description = ( $ phonePrefixDescriptions !== null ) ? $ phonePrefixDescriptions -> lookup ( $ number ) : null ; 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 .
|
6,768
|
public static function getMetadataFilter ( $ liteBuild , $ specialBuild ) { if ( $ specialBuild ) { if ( $ liteBuild ) { throw new \ RuntimeException ( 'liteBuild and specialBuild may not both be set' ) ; } return MetadataFilter :: forSpecialBuild ( ) ; } if ( $ liteBuild ) { return MetadataFilter :: forLiteBuild ( ) ; } return MetadataFilter :: emptyFilter ( ) ; }
|
Processes the custom build flags and gets a MetadataFilter which may be used to filter PhoneMetadata objects . Incompatible flag combinations throw RuntimeException .
|
6,769
|
public static function getNationalPrefix ( \ DOMElement $ element ) { return $ element -> hasAttribute ( self :: NATIONAL_PREFIX ) ? $ element -> getAttribute ( self :: NATIONAL_PREFIX ) : '' ; }
|
Returns the national prefix of the provided country element .
|
6,770
|
public static function loadNationalFormat ( PhoneMetadata $ metadata , \ DOMElement $ numberFormatElement , NumberFormat $ format ) { self :: setLeadingDigitsPatterns ( $ numberFormatElement , $ format ) ; $ format -> setPattern ( self :: validateRE ( $ numberFormatElement -> getAttribute ( self :: PATTERN ) ) ) ; $ formatPattern = $ numberFormatElement -> getElementsByTagName ( self :: FORMAT ) ; if ( $ formatPattern -> length != 1 ) { $ countryId = strlen ( $ metadata -> getId ( ) ) > 0 ? $ metadata -> getId ( ) : $ metadata -> getCountryCode ( ) ; throw new \ RuntimeException ( 'Invalid number of format patterns for country: ' . $ countryId ) ; } $ nationalFormat = $ formatPattern -> item ( 0 ) -> firstChild -> nodeValue ; $ format -> setFormat ( $ nationalFormat ) ; }
|
Extracts the pattern for the national format .
|
6,771
|
public static function loadInternationalFormat ( PhoneMetadata $ metadata , \ DOMElement $ numberFormatElement , NumberFormat $ nationalFormat ) { $ intlFormat = new NumberFormat ( ) ; $ intlFormatPattern = $ numberFormatElement -> getElementsByTagName ( self :: INTL_FORMAT ) ; $ hasExplicitIntlFormatDefined = false ; if ( $ intlFormatPattern -> length > 1 ) { $ countryId = strlen ( $ metadata -> getId ( ) ) > 0 ? $ metadata -> getId ( ) : $ metadata -> getCountryCode ( ) ; throw new \ RuntimeException ( 'Invalid number of intlFormat patterns for country: ' . $ countryId ) ; } if ( $ intlFormatPattern -> length == 0 ) { $ intlFormat -> mergeFrom ( $ nationalFormat ) ; } else { $ intlFormat -> setPattern ( $ numberFormatElement -> getAttribute ( self :: PATTERN ) ) ; self :: setLeadingDigitsPatterns ( $ numberFormatElement , $ intlFormat ) ; $ intlFormatPatternValue = $ intlFormatPattern -> item ( 0 ) -> firstChild -> nodeValue ; if ( $ intlFormatPatternValue !== 'NA' ) { $ intlFormat -> setFormat ( $ intlFormatPatternValue ) ; } $ hasExplicitIntlFormatDefined = true ; } if ( $ intlFormat -> hasFormat ( ) ) { $ metadata -> addIntlNumberFormat ( $ intlFormat ) ; } return $ hasExplicitIntlFormatDefined ; }
|
Extracts the pattern for international format . If there is no intlFormat default to using the national format . If the intlFormat is set to NA the intlFormat should be ignored .
|
6,772
|
private static function parsePossibleLengthStringToSet ( $ possibleLengthString ) { if ( strlen ( $ possibleLengthString ) === 0 ) { throw new \ RuntimeException ( 'Empty possibleLength string found.' ) ; } $ lengths = explode ( ',' , $ possibleLengthString ) ; $ lengthSet = array ( ) ; $ lengthLength = count ( $ lengths ) ; for ( $ i = 0 ; $ i < $ lengthLength ; $ i ++ ) { $ lengthSubstring = $ lengths [ $ i ] ; if ( strlen ( $ lengthSubstring ) === 0 ) { throw new \ RuntimeException ( 'Leading, trailing or adjacent commas in possible ' . "length string {$possibleLengthString}, these should only separate numbers or ranges." ) ; } if ( substr ( $ lengthSubstring , 0 , 1 ) === '[' ) { if ( substr ( $ lengthSubstring , - 1 ) !== ']' ) { throw new \ RuntimeException ( "Missing end of range character in possible length string {$possibleLengthString}." ) ; } $ minMax = explode ( '-' , substr ( $ lengthSubstring , 1 , - 1 ) ) ; if ( count ( $ minMax ) !== 2 ) { throw new \ RuntimeException ( "Ranges must have exactly one - character: missing for {$possibleLengthString}." ) ; } $ min = ( int ) $ minMax [ 0 ] ; $ max = ( int ) $ minMax [ 1 ] ; if ( $ max - $ min < 2 ) { throw new \ RuntimeException ( "The first number in a range should be two or more digits lower than the second. Culprit possibleLength string: {$possibleLengthString}." ) ; } for ( $ j = $ min ; $ j <= $ max ; $ j ++ ) { if ( in_array ( $ j , $ lengthSet ) ) { throw new \ RuntimeException ( "Duplicate length element found ({$j}) in possibleLength string {$possibleLengthString}." ) ; } $ lengthSet [ ] = $ j ; } } else { $ length = $ lengthSubstring ; if ( in_array ( $ length , $ lengthSet ) ) { throw new \ RuntimeException ( "Duplicate length element found ({$length}) in possibleLength string {$possibleLengthString}." ) ; } if ( ! is_numeric ( $ length ) ) { throw new \ RuntimeException ( "For input string \"{$length}\"" ) ; } $ lengthSet [ ] = ( int ) $ length ; } } return $ lengthSet ; }
|
Parses a possible length string into a set of the integers that are covered .
|
6,773
|
public static function setPossibleLengthsGeneralDesc ( PhoneNumberDesc $ generalDesc , $ metadataId , \ DOMElement $ data , $ isShortNumberMetadata ) { $ lengths = array ( ) ; $ localOnlyLengths = array ( ) ; $ generalDescNodes = $ data -> getElementsByTagName ( self :: GENERAL_DESC ) ; if ( $ generalDescNodes -> length > 0 ) { $ generalDescNode = $ generalDescNodes -> item ( 0 ) ; self :: populatePossibleLengthSets ( $ generalDescNode , $ lengths , $ localOnlyLengths ) ; if ( count ( $ lengths ) > 0 || count ( $ localOnlyLengths ) > 0 ) { throw new \ RuntimeException ( "Found possible lengths specified at general desc: this should be derived from child elements. Affected country: {$metadataId}" ) ; } } if ( ! $ isShortNumberMetadata ) { $ allDescData = $ data -> cloneNode ( true ) ; foreach ( self :: $ phoneNumberDescsWithoutMatchingTypes as $ tag ) { $ nodesToRemove = $ allDescData -> getElementsByTagName ( $ tag ) ; if ( $ nodesToRemove -> length > 0 ) { $ allDescData -> removeChild ( $ nodesToRemove -> item ( 0 ) ) ; } } self :: populatePossibleLengthSets ( $ allDescData , $ lengths , $ localOnlyLengths ) ; } else { $ shortCodeDescList = $ data -> getElementsByTagName ( self :: SHORT_CODE ) ; if ( count ( $ shortCodeDescList ) > 0 ) { $ shortCodeDesc = $ shortCodeDescList -> item ( 0 ) ; self :: populatePossibleLengthSets ( $ shortCodeDesc , $ lengths , $ localOnlyLengths ) ; } if ( count ( $ localOnlyLengths ) > 0 ) { throw new \ RuntimeException ( 'Found local-only lengths in short-number metadata' ) ; } } self :: setPossibleLengths ( $ lengths , $ localOnlyLengths , null , $ generalDesc ) ; }
|
Sets possible lengths in the general description derived from certain child elements
|
6,774
|
private static function setPossibleLengths ( $ lengths , $ localOnlyLengths , PhoneNumberDesc $ parentDesc = null , PhoneNumberDesc $ desc ) { $ desc -> clearPossibleLength ( ) ; $ desc -> clearPossibleLengthLocalOnly ( ) ; if ( $ parentDesc === null || ! self :: arePossibleLengthsEqual ( $ lengths , $ parentDesc ) ) { foreach ( $ lengths as $ length ) { if ( $ parentDesc === null || in_array ( $ length , $ parentDesc -> getPossibleLength ( ) ) ) { $ desc -> addPossibleLength ( $ length ) ; } else { throw new \ RuntimeException ( "Out-of-range possible length found ({$length}), parent lengths " . implode ( ',' , $ parentDesc -> getPossibleLength ( ) ) ) ; } } } foreach ( $ localOnlyLengths as $ length ) { if ( ! in_array ( $ length , $ lengths ) ) { if ( $ parentDesc === null || in_array ( $ length , $ parentDesc -> getPossibleLength ( ) ) || in_array ( $ length , $ parentDesc -> getPossibleLengthLocalOnly ( ) ) ) { $ desc -> addPossibleLengthLocalOnly ( $ length ) ; } else { throw new \ RuntimeException ( "Out-of-range local-only possible length found ({$length}), parent length {$parentDesc->getPossibleLengthLocalOnly()}" ) ; } } } }
|
Sets the possible length fields in the metadata from the sets of data passed in . Checks that the length is covered by the parent phone number description element if one is present and if the lengths are exactly the same as this they are not filled in for efficiency reasons .
|
6,775
|
private function parseTextFile ( $ filePath , \ Closure $ handler ) { if ( ! file_exists ( $ filePath ) || ! is_readable ( $ filePath ) ) { throw new \ InvalidArgumentException ( "File '{$filePath}' does not exist" ) ; } $ data = file ( $ filePath ) ; $ countryData = array ( ) ; foreach ( $ data as $ line ) { $ line = str_replace ( array ( "\n" , "\r" ) , '' , $ line ) ; $ line = trim ( $ line ) ; if ( strlen ( $ line ) == 0 || substr ( $ line , 0 , 1 ) == '#' ) { continue ; } if ( strpos ( $ line , '|' ) ) { $ parts = explode ( '|' , $ line ) ; $ prefix = $ parts [ 0 ] ; $ location = $ parts [ 1 ] ; $ handler ( $ prefix , $ location ) ; } } return $ countryData ; }
|
Reads phone prefix data from the provides file path and invokes the given handler for each mapping read .
|
6,776
|
private function makeDataFallbackToEnglish ( $ textFile , & $ mappings ) { $ englishPath = $ this -> getEnglishDataPath ( $ textFile ) ; if ( $ textFile == $ englishPath || ! file_exists ( $ this -> getFilePath ( $ englishPath ) ) ) { return ; } $ countryCode = substr ( $ textFile , 3 , 2 ) ; if ( ! array_key_exists ( $ countryCode , $ this -> englishMaps ) ) { $ englishMap = $ this -> readMappingsFromFile ( $ englishPath ) ; $ this -> englishMaps [ $ countryCode ] = $ englishMap ; } $ this -> compressAccordingToEnglishData ( $ this -> englishMaps [ $ countryCode ] , $ mappings ) ; }
|
Compress the provided mappings according to the English data file if any .
|
6,777
|
private function getPhonePrefixLanguagePairFromFilename ( $ outputFile ) { $ parts = explode ( DIRECTORY_SEPARATOR , $ outputFile ) ; $ returnObj = new \ stdClass ( ) ; $ returnObj -> language = $ parts [ 0 ] ; $ returnObj -> prefix = $ this -> getCountryCodeFromTextFileName ( $ parts [ 1 ] ) ; return $ returnObj ; }
|
Extracts the phone prefix and the language code contained in the provided file name .
|
6,778
|
public function getNameForValidNumber ( PhoneNumber $ number , $ languageCode ) { $ languageStr = Locale :: getPrimaryLanguage ( $ languageCode ) ; $ scriptStr = '' ; $ regionStr = Locale :: getRegion ( $ languageCode ) ; return $ this -> prefixFileReader -> getDescriptionForNumber ( $ number , $ languageStr , $ scriptStr , $ regionStr ) ; }
|
Returns a carrier name for the given phone number in the language provided . The carrier name is the one the number was originally allocated to however if the country supports mobile number portability the number might not belong to the returned carrier anymore . If no mapping is found an empty string is returned .
|
6,779
|
protected function isMobile ( $ numberType ) { return ( $ numberType === PhoneNumberType :: MOBILE || $ numberType === PhoneNumberType :: FIXED_LINE_OR_MOBILE || $ numberType === PhoneNumberType :: PAGER ) ; }
|
Checks if the supplied number type supports carrier lookup .
|
6,780
|
protected function getRegionCodesForCountryCode ( $ countryCallingCode ) { if ( ! array_key_exists ( $ countryCallingCode , $ this -> countryCallingCodeToRegionCodeMap ) ) { $ regionCodes = null ; } else { $ regionCodes = $ this -> countryCallingCodeToRegionCodeMap [ $ countryCallingCode ] ; } return ( $ regionCodes === null ) ? array ( ) : $ regionCodes ; }
|
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 .
|
6,781
|
protected function regionDialingFromMatchesNumber ( PhoneNumber $ number , $ regionDialingFrom ) { $ regionCodes = $ this -> getRegionCodesForCountryCode ( $ number -> getCountryCode ( ) ) ; return in_array ( $ regionDialingFrom , $ regionCodes ) ; }
|
Helper method to check that the country calling code of the number matches the region it s being dialed from .
|
6,782
|
public function getExampleShortNumber ( $ regionCode ) { $ phoneMetadata = $ this -> getMetadataForRegion ( $ regionCode ) ; if ( $ phoneMetadata === null ) { return '' ; } $ desc = $ phoneMetadata -> getShortCode ( ) ; if ( $ desc !== null && $ desc -> hasExampleNumber ( ) ) { return $ desc -> getExampleNumber ( ) ; } return '' ; }
|
Gets a valid short number for the specified region .
|
6,783
|
public function getExampleShortNumberForCost ( $ regionCode , $ cost ) { $ phoneMetadata = $ this -> getMetadataForRegion ( $ regionCode ) ; if ( $ phoneMetadata === null ) { return '' ; } $ desc = null ; switch ( $ cost ) { case ShortNumberCost :: TOLL_FREE : $ desc = $ phoneMetadata -> getTollFree ( ) ; break ; case ShortNumberCost :: STANDARD_RATE : $ desc = $ phoneMetadata -> getStandardRate ( ) ; break ; case ShortNumberCost :: PREMIUM_RATE : $ desc = $ phoneMetadata -> getPremiumRate ( ) ; break ; default : break ; } if ( $ desc !== null && $ desc -> hasExampleNumber ( ) ) { return $ desc -> getExampleNumber ( ) ; } return '' ; }
|
Gets a valid short number for the specified cost category .
|
6,784
|
protected function getRegionCodeForShortNumberFromRegionList ( PhoneNumber $ number , $ regionCodes ) { if ( count ( $ regionCodes ) == 0 ) { return null ; } if ( count ( $ regionCodes ) == 1 ) { return $ regionCodes [ 0 ] ; } $ nationalNumber = $ this -> getNationalSignificantNumber ( $ number ) ; foreach ( $ regionCodes as $ regionCode ) { $ phoneMetadata = $ this -> getMetadataForRegion ( $ regionCode ) ; if ( $ phoneMetadata !== null && $ this -> matchesPossibleNumberAndNationalNumber ( $ nationalNumber , $ phoneMetadata -> getShortCode ( ) ) ) { return $ regionCode ; } } return 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 .
|
6,785
|
public function isValidShortNumberForRegion ( PhoneNumber $ number , $ regionDialingFrom ) { if ( ! $ this -> regionDialingFromMatchesNumber ( $ number , $ regionDialingFrom ) ) { return false ; } $ phoneMetadata = $ this -> getMetadataForRegion ( $ regionDialingFrom ) ; if ( $ phoneMetadata === null ) { return false ; } $ shortNumber = $ this -> getNationalSignificantNumber ( $ number ) ; $ generalDesc = $ phoneMetadata -> getGeneralDesc ( ) ; if ( ! $ this -> matchesPossibleNumberAndNationalNumber ( $ shortNumber , $ generalDesc ) ) { return false ; } $ shortNumberDesc = $ phoneMetadata -> getShortCode ( ) ; return $ this -> matchesPossibleNumberAndNationalNumber ( $ shortNumber , $ shortNumberDesc ) ; }
|
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 .
|
6,786
|
protected static function limit ( $ lower , $ upper ) { if ( ( $ lower < 0 ) || ( $ upper <= 0 ) || ( $ upper < $ lower ) ) { throw new \ InvalidArgumentException ( ) ; } return '{' . $ lower . ',' . $ upper . '}' ; }
|
Helper function to generate regular expression with an upper and lower limit .
|
6,787
|
public static function isLatinLetter ( $ letter ) { if ( preg_match ( '/\p{L}/u' , $ letter ) !== 1 && preg_match ( '/\p{Mn}/u' , $ letter ) !== 1 ) { return false ; } return ( preg_match ( '/\p{Latin}/u' , $ letter ) === 1 ) || ( preg_match ( '/\pM+/u' , $ letter ) === 1 ) ; }
|
Helper method to determine if a character is a Latin - script letter or not . For our purposes combining marks should also return true since we assume they have been added to a preceding Latin character .
|
6,788
|
protected static function getNationalNumberGroups ( PhoneNumberUtil $ util , PhoneNumber $ number , NumberFormat $ formattingPattern = null ) { if ( $ formattingPattern === null ) { $ rfc3966Format = $ util -> format ( $ number , PhoneNumberFormat :: RFC3966 ) ; $ endIndex = mb_strpos ( $ rfc3966Format , ';' ) ; if ( $ endIndex === false ) { $ endIndex = mb_strlen ( $ rfc3966Format ) ; } $ startIndex = mb_strpos ( $ rfc3966Format , '-' ) + 1 ; return explode ( '-' , mb_substr ( $ rfc3966Format , $ startIndex , $ endIndex - $ startIndex ) ) ; } $ nationalSignificantNumber = $ util -> getNationalSignificantNumber ( $ number ) ; return explode ( '-' , $ util -> formatNsnUsingPattern ( $ nationalSignificantNumber , $ formattingPattern , PhoneNumberFormat :: RFC3966 ) ) ; }
|
Helper method to get the national - number part of a number formatted without any national prefix and return it as a set of digit blocks that would be formatted together .
|
6,789
|
public function clear ( ) { $ this -> clearCountryCode ( ) ; $ this -> clearNationalNumber ( ) ; $ this -> clearExtension ( ) ; $ this -> clearItalianLeadingZero ( ) ; $ this -> clearNumberOfLeadingZeros ( ) ; $ this -> clearRawInput ( ) ; $ this -> clearCountryCodeSource ( ) ; $ this -> clearPreferredDomesticCarrierCode ( ) ; return $ this ; }
|
Clears this phone number .
|
6,790
|
public function mergeFrom ( PhoneNumber $ other ) { if ( $ other -> hasCountryCode ( ) ) { $ this -> setCountryCode ( $ other -> getCountryCode ( ) ) ; } if ( $ other -> hasNationalNumber ( ) ) { $ this -> setNationalNumber ( $ other -> getNationalNumber ( ) ) ; } if ( $ other -> hasExtension ( ) ) { $ this -> setExtension ( $ other -> getExtension ( ) ) ; } if ( $ other -> hasItalianLeadingZero ( ) ) { $ this -> setItalianLeadingZero ( $ other -> isItalianLeadingZero ( ) ) ; } if ( $ other -> hasNumberOfLeadingZeros ( ) ) { $ this -> setNumberOfLeadingZeros ( $ other -> getNumberOfLeadingZeros ( ) ) ; } if ( $ other -> hasRawInput ( ) ) { $ this -> setRawInput ( $ other -> getRawInput ( ) ) ; } if ( $ other -> hasCountryCodeSource ( ) ) { $ this -> setCountryCodeSource ( $ other -> getCountryCodeSource ( ) ) ; } if ( $ other -> hasPreferredDomesticCarrierCode ( ) ) { $ this -> setPreferredDomesticCarrierCode ( $ other -> getPreferredDomesticCarrierCode ( ) ) ; } return $ this ; }
|
Merges the information from another phone number into this phone number .
|
6,791
|
public function setNumberOfLeadingZeros ( $ value ) { $ this -> hasNumberOfLeadingZeros = true ; $ this -> numberOfLeadingZeros = ( int ) $ value ; return $ this ; }
|
Sets the number of leading zeros of this phone number .
|
6,792
|
public function equals ( PhoneNumber $ other ) { $ sameType = get_class ( $ other ) == get_class ( $ this ) ; $ sameCountry = $ this -> hasCountryCode ( ) == $ other -> hasCountryCode ( ) && ( ! $ this -> hasCountryCode ( ) || $ this -> getCountryCode ( ) == $ other -> getCountryCode ( ) ) ; $ sameNational = $ this -> hasNationalNumber ( ) == $ other -> hasNationalNumber ( ) && ( ! $ this -> hasNationalNumber ( ) || $ this -> getNationalNumber ( ) == $ other -> getNationalNumber ( ) ) ; $ sameExt = $ this -> hasExtension ( ) == $ other -> hasExtension ( ) && ( ! $ this -> hasExtension ( ) || $ this -> hasExtension ( ) == $ other -> hasExtension ( ) ) ; $ sameLead = $ this -> hasItalianLeadingZero ( ) == $ other -> hasItalianLeadingZero ( ) && ( ! $ this -> hasItalianLeadingZero ( ) || $ this -> isItalianLeadingZero ( ) == $ other -> isItalianLeadingZero ( ) ) ; $ sameZeros = $ this -> getNumberOfLeadingZeros ( ) == $ other -> getNumberOfLeadingZeros ( ) ; $ sameRaw = $ this -> hasRawInput ( ) == $ other -> hasRawInput ( ) && ( ! $ this -> hasRawInput ( ) || $ this -> getRawInput ( ) == $ other -> getRawInput ( ) ) ; $ sameCountrySource = $ this -> hasCountryCodeSource ( ) == $ other -> hasCountryCodeSource ( ) && ( ! $ this -> hasCountryCodeSource ( ) || $ this -> getCountryCodeSource ( ) == $ other -> getCountryCodeSource ( ) ) ; $ samePrefCar = $ this -> hasPreferredDomesticCarrierCode ( ) == $ other -> hasPreferredDomesticCarrierCode ( ) && ( ! $ this -> hasPreferredDomesticCarrierCode ( ) || $ this -> getPreferredDomesticCarrierCode ( ) == $ other -> getPreferredDomesticCarrierCode ( ) ) ; return $ sameType && $ sameCountry && $ sameNational && $ sameExt && $ sameLead && $ sameZeros && $ sameRaw && $ sameCountrySource && $ samePrefCar ; }
|
Returns whether this phone number is equal to another .
|
6,793
|
private function parseTextFile ( ) { $ data = file ( $ this -> inputTextFile ) ; $ timeZoneMap = array ( ) ; foreach ( $ data as $ line ) { $ line = str_replace ( array ( "\n" , "\r" ) , '' , $ line ) ; $ line = trim ( $ line ) ; if ( strlen ( $ line ) == 0 || substr ( $ line , 0 , 1 ) == '#' ) { continue ; } if ( strpos ( $ line , '|' ) ) { $ parts = explode ( '|' , $ line ) ; $ prefix = $ parts [ 0 ] ; $ timezone = $ parts [ 1 ] ; $ timeZoneMap [ $ prefix ] = $ timezone ; } } return $ timeZoneMap ; }
|
Reads phone prefix data from the provided input stream and returns a SortedMap with the prefix to time zones mappings .
|
6,794
|
public function getDescriptionForNumber ( PhoneNumber $ number , $ locale , $ userRegion = null ) { $ numberType = $ this -> phoneUtil -> getNumberType ( $ number ) ; if ( $ numberType === PhoneNumberType :: UNKNOWN ) { return '' ; } if ( ! $ this -> phoneUtil -> isNumberGeographical ( $ numberType , $ number -> getCountryCode ( ) ) ) { return $ this -> getCountryNameForNumber ( $ number , $ locale ) ; } return $ this -> getDescriptionForValidNumber ( $ number , $ locale , $ userRegion ) ; }
|
As per getDescriptionForValidNumber but explicitly checks the validity of the number passed in .
|
6,795
|
protected function getCountryNameForNumber ( PhoneNumber $ number , $ locale ) { $ regionCodes = $ this -> phoneUtil -> getRegionCodesForCountryCode ( $ number -> getCountryCode ( ) ) ; if ( count ( $ regionCodes ) === 1 ) { return $ this -> getRegionDisplayName ( $ regionCodes [ 0 ] , $ locale ) ; } $ regionWhereNumberIsValid = 'ZZ' ; foreach ( $ regionCodes as $ regionCode ) { if ( $ this -> phoneUtil -> isValidNumberForRegion ( $ number , $ regionCode ) ) { if ( $ regionWhereNumberIsValid !== 'ZZ' ) { return '' ; } $ regionWhereNumberIsValid = $ regionCode ; } } return $ this -> getRegionDisplayName ( $ regionWhereNumberIsValid , $ locale ) ; }
|
Returns the customary display name in the given language for the given territory the phone number is from . If it could be from many territories nothing is returned .
|
6,796
|
protected function getRegionDisplayName ( $ regionCode , $ locale ) { if ( $ regionCode === null || $ regionCode == 'ZZ' || $ regionCode === PhoneNumberUtil :: REGION_CODE_FOR_NON_GEO_ENTITY ) { return '' ; } return Locale :: getDisplayRegion ( '-' . $ regionCode , $ locale ) ; }
|
Returns the customary display name in the given language for the given region .
|
6,797
|
public function getDescriptionForValidNumber ( PhoneNumber $ number , $ locale , $ userRegion = null ) { $ 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 ) ) ) ) { $ nationalNumber = substr ( $ nationalNumber , strlen ( $ mobileToken ) ) ; $ region = $ this -> phoneUtil -> getRegionCodeForCountryCode ( $ number -> getCountryCode ( ) ) ; try { $ copiedNumber = $ this -> phoneUtil -> parse ( $ nationalNumber , $ region ) ; } catch ( NumberParseException $ e ) { $ 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 ) ; } return $ this -> getRegionDisplayName ( $ regionCode , $ locale ) ; }
|
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 .
|
6,798
|
public static function expandIPv6 ( $ ip ) { $ addr = inet_pton ( $ ip ) ; if ( $ addr === false ) { return false ; } $ hex = unpack ( 'H*hex' , $ addr ) ; return substr ( preg_replace ( '/([a-f0-9]{4})/i' , '$1:' , $ hex [ 'hex' ] ) , 0 , - 1 ) ; }
|
Expands an IPv6 address to it s full notation .
|
6,799
|
public function compose ( MessageInterface $ message , $ params = [ ] ) { $ this -> message = $ message ; if ( is_array ( $ this -> viewName ) ) { if ( isset ( $ this -> viewName [ 'html' ] ) ) { $ html = $ this -> render ( $ this -> viewName [ 'html' ] , $ params , $ this -> htmlLayout ) ; } if ( isset ( $ this -> viewName [ 'text' ] ) ) { $ text = $ this -> render ( $ this -> viewName [ 'text' ] , $ params , $ this -> textLayout ) ; } } else { $ html = $ this -> render ( $ this -> viewName , $ params , $ this -> htmlLayout ) ; } if ( isset ( $ html ) ) { $ this -> message -> setHtmlBody ( $ html ) ; } if ( isset ( $ text ) ) { $ this -> message -> setTextBody ( $ text ) ; } elseif ( isset ( $ html ) ) { if ( preg_match ( '~<body[^>]*>(.*?)</body>~is' , $ html , $ match ) ) { $ html = $ match [ 1 ] ; } $ html = preg_replace ( '~<((style|script))[^>]*>(.*?)</\1>~is' , '' , $ html ) ; $ text = html_entity_decode ( strip_tags ( $ html ) , ENT_QUOTES | ENT_HTML5 ) ; $ text = preg_replace ( "~^[ \t]+~m" , '' , trim ( $ text ) ) ; $ text = preg_replace ( '~\R\R+~mu' , "\n\n" , $ text ) ; $ this -> message -> setTextBody ( $ text ) ; } }
|
Composes the given mail message according to this template .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.