1 | <?php |
||
12 | class PhoneNumberOfflineGeocoder |
||
13 | { |
||
14 | const MAPPING_DATA_DIRECTORY = '/data'; |
||
15 | /** |
||
16 | * @var PhoneNumberOfflineGeocoder |
||
17 | */ |
||
18 | protected static $instance; |
||
19 | /** |
||
20 | * @var PhoneNumberUtil |
||
21 | */ |
||
22 | protected $phoneUtil; |
||
23 | /** |
||
24 | * @var PrefixFileReader |
||
25 | */ |
||
26 | protected $prefixFileReader = null; |
||
27 | |||
28 | 246 | protected function __construct($phonePrefixDataDirectory) |
|
34 | |||
35 | /** |
||
36 | * Gets a PhoneNumberOfflineGeocoder instance to carry out international phone number geocoding. |
||
37 | * |
||
38 | * <p>The PhoneNumberOfflineGeocoder is implemented as a singleton. Therefore, calling this method |
||
39 | * multiple times will only result in one instance being created. |
||
40 | * |
||
41 | * @param string $mappingDir (Optional) Mapping Data Directory |
||
42 | * @return PhoneNumberOfflineGeocoder |
||
43 | */ |
||
44 | 251 | public static function getInstance($mappingDir = self::MAPPING_DATA_DIRECTORY) |
|
45 | { |
||
46 | 251 | if (static::$instance === null) { |
|
47 | 246 | static::$instance = new static($mappingDir); |
|
48 | 246 | } |
|
49 | |||
50 | 251 | return static::$instance; |
|
51 | } |
||
52 | |||
53 | 246 | public static function resetInstance() |
|
57 | |||
58 | /** |
||
59 | * As per getDescriptionForValidNumber, but explicitly checks the validity of the number |
||
60 | * passed in. |
||
61 | * |
||
62 | * |
||
63 | * @see getDescriptionForValidNumber |
||
64 | * @param PhoneNumber $number a valid phone number for which we want to get a text description |
||
65 | * @param string $locale the language code for which the description should be written |
||
66 | * @param string $userRegion the region code for a given user. This region will be omitted from the |
||
67 | * description if the phone number comes from this region. It is a two-letter uppercase ISO |
||
68 | * country code as defined by ISO 3166-1. |
||
69 | * @return string a text description for the given language code for the given phone number, or empty |
||
70 | * string if the number passed in is invalid |
||
71 | */ |
||
72 | 17 | public function getDescriptionForNumber(PhoneNumber $number, $locale, $userRegion = null) |
|
84 | |||
85 | /** |
||
86 | * Returns the customary display name in the given language for the given territory the phone |
||
87 | * number is from. If it could be from many territories, nothing is returned. |
||
88 | * |
||
89 | * @param PhoneNumber $number |
||
90 | * @param $locale |
||
91 | * @return string |
||
92 | */ |
||
93 | 9 | protected function getCountryNameForNumber(PhoneNumber $number, $locale) |
|
115 | |||
116 | /** |
||
117 | * Returns the customary display name in the given language for the given region. |
||
118 | * |
||
119 | * @param $regionCode |
||
120 | * @param $locale |
||
121 | * @return string |
||
122 | */ |
||
123 | 242 | protected function getRegionDisplayName($regionCode, $locale) |
|
134 | |||
135 | /** |
||
136 | * Returns a text description for the given phone number, in the language provided. The |
||
137 | * description might consist of the name of the country where the phone number is from, or the |
||
138 | * name of the geographical area the phone number is from if more detailed information is |
||
139 | * available. |
||
140 | * |
||
141 | * <p>This method assumes the validity of the number passed in has already been checked, and that |
||
142 | * the number is suitable for geocoding. We consider fixed-line and mobile numbers possible |
||
143 | * candidates for geocoding. |
||
144 | * |
||
145 | * <p>If $userRegion is set, we also consider the region of the user. If the phone number is from |
||
146 | * the same region as the user, only a lower-level description will be returned, if one exists. |
||
147 | * Otherwise, the phone number's region will be returned, with optionally some more detailed |
||
148 | * information. |
||
149 | * |
||
150 | * <p>For example, for a user from the region "US" (United States), we would show "Mountain View, |
||
151 | * CA" for a particular number, omitting the United States from the description. For a user from |
||
152 | * the United Kingdom (region "GB"), for the same number we may show "Mountain View, CA, United |
||
153 | * States" or even just "United States". |
||
154 | * |
||
155 | * @param PhoneNumber $number a valid phone number for which we want to get a text description |
||
156 | * @param string $locale the language code for which the description should be written |
||
157 | * @param string $userRegion the region code for a given user. This region will be omitted from the |
||
158 | * description if the phone number comes from this region. It is a two-letter uppercase ISO |
||
159 | * country code as defined by ISO 3166-1. |
||
160 | * @return string a text description for the given language code for the given phone number |
||
161 | */ |
||
162 | 245 | public function getDescriptionForValidNumber(PhoneNumber $number, $locale, $userRegion = null) |
|
198 | } |
||
199 |