/** * @param string $phone * @param string|NULL $country * @param int|NULL $format * * @return string */ public function phone($phone, $country = 'AUTO', $format = Phone\Phone::FORMAT_INTERNATIONAL) { $country = strtoupper($country); if ((strlen($country) !== 2 || !ctype_alpha($country) || !ctype_upper($country)) && $country !== 'AUTO') { $format = $country; $country = 'AUTO'; } return $this->phone->format($phone, $country, $format); }
/** * @param string $country * * @return string * * @throws Exceptions\NoValidCountryException */ protected function validateCountry($country) { // Country code have to be upper-cased $country = strtoupper($country); if (strlen($country) === 2 && ctype_alpha($country) && ctype_upper($country) && in_array($country, $this->phoneUtils->getSupportedCountries()) || $country === 'AUTO') { return $country; } else { throw new Exceptions\NoValidCountryException('Provided country code "' . $country . '" is not valid. Provide valid country code or AUTO for automatic detection.'); } }