| 1 |
<?php |
| 2 |
/** |
| 3 |
* Hosting environment handling. |
| 4 |
* |
| 5 |
* @package System |
| 6 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Decalog\System; |
| 11 |
|
| 12 |
/** |
| 13 |
* The class responsible to manage and detect hosting environment. |
| 14 |
* |
| 15 |
* @package System |
| 16 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 17 |
* @since 1.0.0 |
| 18 |
*/ |
| 19 |
class Hosting { |
| 20 |
|
| 21 |
|
| 22 |
/** |
| 23 |
* Initializes the class and set its properties. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
*/ |
| 27 |
public function __construct() { |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Check if Cloudflare Geoip is enabled. |
| 32 |
* |
| 33 |
* @return bool True if Cloudflare Geoip is enabled. |
| 34 |
* @since 1.0.0 |
| 35 |
*/ |
| 36 |
public static function is_cloudflare_geoip_enabled() { |
| 37 |
return array_key_exists( 'HTTP_CF_IPCOUNTRY', $_SERVER ) || array_key_exists( 'CF-IPCountry', $_SERVER ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Check if Cloudfront (AWS) Geoip is enabled. |
| 42 |
* |
| 43 |
* @return bool True if Cloudfront Geoip is enabled. |
| 44 |
* @since 1.0.0 |
| 45 |
*/ |
| 46 |
public static function is_cloudfront_geoip_enabled() { |
| 47 |
return array_key_exists( 'CloudFront-Viewer-Country', $_SERVER ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Check if Google LB Geoip is enabled. |
| 52 |
* |
| 53 |
* @return bool True if Google Geoip is enabled. |
| 54 |
* @since 2.3.0 |
| 55 |
*/ |
| 56 |
public static function is_googlelb_geoip_enabled() { |
| 57 |
return array_key_exists( 'X-Client-Geo-Location', $_SERVER ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Check if Apache Geoip is enabled. |
| 62 |
* |
| 63 |
* @return bool True if Cloudfront Geoip is enabled. |
| 64 |
* @since 1.0.0 |
| 65 |
*/ |
| 66 |
public static function is_apache_geoip_enabled() { |
| 67 |
return array_key_exists( 'GEOIP_COUNTRY_CODE', $_SERVER ); |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|