1 | <?php |
||
16 | class PhoneNumberToCarrierMapper |
||
17 | { |
||
18 | /** |
||
19 | * @var PhoneNumberToCarrierMapper[] |
||
20 | */ |
||
21 | protected static $instance = array(); |
||
22 | |||
23 | const MAPPING_DATA_DIRECTORY = '/carrier/data/'; |
||
24 | |||
25 | /** |
||
26 | * @var PhoneNumberUtil |
||
27 | */ |
||
28 | protected $phoneUtil; |
||
29 | /** |
||
30 | * @var PrefixFileReader |
||
31 | */ |
||
32 | protected $prefixFileReader; |
||
33 | |||
34 | 2 | protected function __construct($phonePrefixDataDirectory) |
|
39 | |||
40 | /** |
||
41 | * Gets a {@link PhoneNumberToCarrierMapper} instance to carry out international carrier lookup. |
||
42 | * |
||
43 | * <p> The {@link PhoneNumberToCarrierMapper} is implemented as a singleton. Therefore, calling |
||
44 | * this method multiple times will only result in one instance being created. |
||
45 | * |
||
46 | * @param string $mappingDir |
||
47 | * @return PhoneNumberToCarrierMapper |
||
48 | */ |
||
49 | 9 | public static function getInstance($mappingDir = self::MAPPING_DATA_DIRECTORY) |
|
57 | |||
58 | /** |
||
59 | * Returns a carrier name for the given phone number, in the language provided. The carrier name |
||
60 | * is the one the number was originally allocated to, however if the country supports mobile |
||
61 | * number portability the number might not belong to the returned carrier anymore. If no mapping |
||
62 | * is found an empty string is returned. |
||
63 | * |
||
64 | * <p>This method assumes the validity of the number passed in has already been checked, and that |
||
65 | * the number is suitable for carrier lookup. We consider mobile and pager numbers possible |
||
66 | * candidates for carrier lookup. |
||
67 | * |
||
68 | * @param PhoneNumber $number a valid phone number for which we want to get a carrier name |
||
69 | * @param string $languageCode the language code in which the name should be written |
||
70 | * @return string a carrier name for the given phone number |
||
71 | */ |
||
72 | 8 | public function getNameForValidNumber(PhoneNumber $number, $languageCode) |
|
80 | |||
81 | |||
82 | /** |
||
83 | * Gets the name of the carrier for the given phone number, in the language provided. As per |
||
84 | * {@link #getNameForValidNumber(PhoneNumber, Locale)} but explicitly checks the validity of |
||
85 | * the number passed in. |
||
86 | * |
||
87 | * @param PhoneNumber $number The phone number for which we want to get a carrier name |
||
88 | * @param string $languageCode Language code for which the description should be written |
||
89 | * @return string a carrier name for the given phone number, or empty string if the number passed in is |
||
90 | * invalid |
||
91 | */ |
||
92 | 9 | public function getNameForNumber(PhoneNumber $number, $languageCode) |
|
100 | |||
101 | /** |
||
102 | * Gets the name of the carrier for the given phone number only when it is 'safe' to display to |
||
103 | * users. A carrier name is considered safe if the number is valid and for a region that doesn't |
||
104 | * support |
||
105 | * {@linkplain http://en.wikipedia.org/wiki/Mobile_number_portability mobile number portability}. |
||
106 | * |
||
107 | * @param $number PhoneNumber the phone number for which we want to get a carrier name |
||
108 | * @param $languageCode String the language code in which the name should be written |
||
109 | * @return string a carrier name that is safe to display to users, or the empty string |
||
110 | */ |
||
111 | 2 | public function getSafeDisplayName(PhoneNumber $number, $languageCode) |
|
119 | |||
120 | /** |
||
121 | * Checks if the supplied number type supports carrier lookup. |
||
122 | * @param int $numberType A PhoneNumberType int |
||
123 | * @return bool |
||
124 | */ |
||
125 | 9 | protected function isMobile($numberType) |
|
132 | } |
||
133 |