1 | <?php |
||
12 | class PrefixFileReader |
||
13 | { |
||
14 | protected $phonePrefixDataDirectory; |
||
15 | /** |
||
16 | * The mappingFileProvider knows for which combination of countryCallingCode and language a phone |
||
17 | * prefix mapping file is available in the file system, so that a file can be loaded when needed. |
||
18 | * @var MappingFileProvider |
||
19 | */ |
||
20 | protected $mappingFileProvider; |
||
21 | /** |
||
22 | * A mapping from countryCallingCode_lang to the corresponding phone prefix map that has been |
||
23 | * loaded. |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $availablePhonePrefixMaps = array(); |
||
27 | |||
28 | 253 | public function __construct($phonePrefixDataDirectory) |
|
33 | |||
34 | 253 | protected function loadMappingFileProvider() |
|
45 | |||
46 | |||
47 | /** |
||
48 | * @param $prefixMapKey |
||
49 | * @param $language |
||
50 | * @param $script |
||
51 | * @param $region |
||
52 | * @return PhonePrefixMap|null |
||
53 | */ |
||
54 | 25 | public function getPhonePrefixDescriptions($prefixMapKey, $language, $script, $region) |
|
55 | { |
||
56 | 25 | $fileName = $this->mappingFileProvider->getFileName($prefixMapKey, $language, $script, $region); |
|
57 | 25 | if (strlen($fileName) == 0) { |
|
58 | 9 | return null; |
|
59 | } |
||
60 | |||
61 | 20 | if (!isset($this->availablePhonePrefixMaps[$fileName])) { |
|
62 | 17 | $this->loadPhonePrefixMapFromFile($fileName); |
|
63 | } |
||
64 | |||
65 | 20 | return $this->availablePhonePrefixMaps[$fileName]; |
|
66 | } |
||
67 | |||
68 | 17 | protected function loadPhonePrefixMapFromFile($fileName) |
|
80 | |||
81 | 14 | public function mayFallBackToEnglish($language) |
|
89 | |||
90 | /** |
||
91 | * Returns a text description in the given language for the given phone number. |
||
92 | * |
||
93 | * @param PhoneNumber $number the phone number for which we want to get a text description |
||
94 | * @param string $language two-letter lowercase ISO language codes as defined by ISO 639-1 |
||
95 | * @param string $script four-letter titlecase (the first letter is uppercase and the rest of the letters |
||
96 | * are lowercase) ISO script codes as defined in ISO 15924 |
||
97 | * @param string $region two-letter uppercase ISO country codes as defined by ISO 3166-1 |
||
98 | * @return string a text description in the given language for the given phone number, or an empty |
||
99 | * string if a description is not available |
||
100 | */ |
||
101 | 25 | public function getDescriptionForNumber(PhoneNumber $number, $language, $script, $region) |
|
130 | } |
||
131 |