Exemple #1
0
 /**
  * @param string $number
  * @param string $country
  * @param string|NULL $locale
  * @param string|NULL $userCountry
  *
  * @return string
  *
  * @throws Exceptions\NoValidCountryException
  * @throws Exceptions\NoValidPhoneException
  */
 public function getLocation($number, $country = 'AUTO', $locale = NULL, $userCountry = NULL)
 {
     if ($this->isValid((string) $number, $country)) {
         $country = strtoupper($country);
         if ($userCountry !== NULL) {
             // Check for valid user country
             $userCountry = $this->validateCountry($userCountry);
         }
         // Parse phone number
         $parsed = $this->phoneNumberUtil->parse((string) $number, $country);
         // Determine locale
         $locale = $locale === NULL && $this->translator && method_exists($this->translator, 'getLocale') ? $this->translator->getLocale() : 'en_US';
         // Get phone number location
         return $this->phoneNumberGeocoder->getDescriptionForNumber($parsed, $locale, $userCountry);
     } else {
         throw new Exceptions\NoValidPhoneException('Provided phone number "' . $number . '" is not valid phone number. Provide valid phone number.');
     }
 }