isWorking() 공개 메소드

Returns true if this provider has been setup correctly, the error message if otherwise.
public isWorking ( ) : boolean | string
리턴 boolean | string
예제 #1
0
파일: Pecl.php 프로젝트: parruc/piwik
 /**
  * Returns true if the PECL module that is installed can be successfully used
  * to get the location of an IP address.
  *
  * @return bool
  */
 public function isWorking()
 {
     // if no no location database is available, this implementation is not setup correctly
     if (!self::isLocationDatabaseAvailable()) {
         $dbDir = dirname(geoip_db_filename(GEOIP_COUNTRY_EDITION)) . '/';
         $quotedDir = "'{$dbDir}'";
         // check if the directory the PECL module is looking for exists
         if (!is_dir($dbDir)) {
             return Piwik::translate('UserCountry_PeclGeoIPNoDBDir', array($quotedDir, "'geoip.custom_directory'"));
         }
         // check if the user named the city database GeoLiteCity.dat
         if (file_exists($dbDir . 'GeoLiteCity.dat')) {
             return Piwik::translate('UserCountry_PeclGeoLiteError', array($quotedDir, "'GeoLiteCity.dat'", "'GeoIPCity.dat'"));
         }
         return Piwik::translate('UserCountry_CannotFindPeclGeoIPDb', array($quotedDir, "'GeoIP.dat'", "'GeoIPCity.dat'"));
     }
     return parent::isWorking();
 }
예제 #2
0
파일: Php.php 프로젝트: carriercomm/piwik
 /**
  * Returns true if this provider has been setup correctly, the error message if
  * otherwise.
  *
  * @return bool|string
  */
 public function isWorking()
 {
     if (!function_exists('mb_internal_encoding')) {
         return Piwik::translate('UserCountry_GeoIPCannotFindMbstringExtension', array('mb_internal_encoding', 'mbstring'));
     }
     $geoIpError = false;
     $catchGeoIpError = function ($errno, $errstr, $errfile, $errline) use(&$geoIpError) {
         $filename = basename($errfile);
         if ($filename == 'geoip.inc' || $filename == 'geoipcity.inc') {
             $geoIpError = array($errno, $errstr, $errfile, $errline);
         } else {
             throw new \Exception("Error in PHP GeoIP provider: {$errstr} on line {$errline} of {$errfile}");
             // unexpected
         }
     };
     // catch GeoIP errors
     set_error_handler($catchGeoIpError);
     $result = parent::isWorking();
     restore_error_handler();
     if ($geoIpError) {
         list($errno, $errstr, $errfile, $errline) = $geoIpError;
         Log::warning("Got GeoIP error when testing PHP GeoIP location provider: %s(%s): %s", $errfile, $errline, $errstr);
         return Piwik::translate('UserCountry_GeoIPIncorrectDatabaseFormat');
     }
     return $result;
 }