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