當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataValidator::is_valid_iso_country_code方法代碼示例

本文整理匯總了PHP中DataValidator::is_valid_iso_country_code方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataValidator::is_valid_iso_country_code方法的具體用法?PHP DataValidator::is_valid_iso_country_code怎麽用?PHP DataValidator::is_valid_iso_country_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataValidator的用法示例。


在下文中一共展示了DataValidator::is_valid_iso_country_code方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setCountry

 /**
  * normalize helper function
  * Setting the country correctly. Country is... kinda important.
  * If we have no country, or nonsense, we try to get something rational
  * through GeoIP lookup.
  */
 protected function setCountry()
 {
     $regen = true;
     $country = '';
     if ($this->isSomething('country')) {
         $country = strtoupper($this->getVal('country'));
         if (DataValidator::is_valid_iso_country_code($country)) {
             $regen = false;
         } else {
             //check to see if it's one of those other codes that comes out of CN, for the logs
             //If this logs annoying quantities of nothing useful, go ahead and kill this whole else block later.
             //we're still going to try to regen.
             $near_countries = array('XX', 'EU', 'AP', 'A1', 'A2', 'O1');
             if (!in_array($country, $near_countries)) {
                 $this->logger->warning(__FUNCTION__ . ": {$country} is not a country, or a recognized placeholder.");
             }
         }
     } else {
         $this->logger->warning(__FUNCTION__ . ': Country not set.');
     }
     //try to regenerate the country if we still don't have a valid one yet
     if ($regen) {
         // If no valid country was passed, try to do GeoIP lookup
         // Requires php5-geoip package
         if (function_exists('geoip_country_code_by_name')) {
             $ip = $this->getVal('user_ip');
             if (WmfFramework::validateIP($ip)) {
                 //I hate @suppression at least as much as you do, but this geoip function is being genuinely horrible.
                 //try/catch did not help me suppress the notice it emits when it can't find a host.
                 //The goggles; They do *nothing*.
                 // TODO: to change error_reporting is less worse?
                 $country = @geoip_country_code_by_name($ip);
                 if (!$country) {
                     $this->logger->warning(__FUNCTION__ . ": GeoIP lookup function found nothing for {$ip}! No country available.");
                 }
             }
         } else {
             $this->logger->warning('GeoIP lookup function is missing! No country available.');
         }
         //still nothing good? Give up.
         if (!DataValidator::is_valid_iso_country_code($country)) {
             $country = 'XX';
         }
     }
     if ($country != $this->getVal('country')) {
         $this->setVal('country', $country);
     }
 }
開發者ID:wikimedia,項目名稱:wikimedia-fundraising-crm-vendor,代碼行數:54,代碼來源:DonationData.php


注:本文中的DataValidator::is_valid_iso_country_code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。