当前位置: 首页>>代码示例>>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;未经允许,请勿转载。