ActiveDonationFormsData.php
5 years ago
DonationData.php
5 years ago
DonationFormsData.php
5 years ago
DonationMetricsData.php
5 years ago
EditedDonationFormsData.php
5 years ago
GivePluginSettingsData.php
5 years ago
PluginsData.php
4 years ago
ServerData.php
5 years ago
ThemeData.php
5 years ago
WebsiteData.php
5 years ago
WebsiteInfoData.php
5 years ago
ServerData.php
77 lines
| 1 | <?php |
| 2 | namespace Give\Tracking\TrackingData; |
| 3 | |
| 4 | use Give\Tracking\Contracts\TrackData; |
| 5 | |
| 6 | /** |
| 7 | * Class ServerData |
| 8 | * |
| 9 | * Represents the server data. |
| 10 | * |
| 11 | * @since 2.10.0 |
| 12 | * @package Give\Tracking\TrackingData |
| 13 | */ |
| 14 | class ServerData implements TrackData { |
| 15 | |
| 16 | /** |
| 17 | * Returns the collection data. |
| 18 | * |
| 19 | * @since 2.10.0 |
| 20 | * |
| 21 | * @return array The collection data. |
| 22 | */ |
| 23 | public function get() { |
| 24 | return $this->getServerData(); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Returns the values with server details. |
| 29 | * |
| 30 | * @since 2.10.0 |
| 31 | * |
| 32 | * @return array Array with the value. |
| 33 | */ |
| 34 | private function getServerData() { |
| 35 | $server_data = []; |
| 36 | |
| 37 | // Validate if the server address is a valid IP-address. |
| 38 | $ipaddress = filter_input( INPUT_SERVER, 'SERVER_ADDR', FILTER_VALIDATE_IP ); |
| 39 | if ( $ipaddress ) { |
| 40 | $server_data['server_ip'] = $ipaddress; |
| 41 | $server_data['server_hostname'] = gethostbyaddr( $ipaddress ); |
| 42 | } |
| 43 | |
| 44 | $server_data['server_os'] = php_uname(); |
| 45 | $server_data['php_version'] = PHP_VERSION; |
| 46 | $server_data = array_merge( $server_data, $this->getCurlInfo() ); |
| 47 | |
| 48 | return $server_data; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns details about the curl version. |
| 53 | * |
| 54 | * @since 2.10.0 |
| 55 | * |
| 56 | * @return array|null The curl info. Or null when curl isn't available.. |
| 57 | */ |
| 58 | private function getCurlInfo() { |
| 59 | if ( ! function_exists( 'curl_version' ) ) { |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | $curl = curl_version(); |
| 64 | |
| 65 | $ssl_support = 1; |
| 66 | if ( ! $curl['features'] && CURL_VERSION_SSL ) { |
| 67 | $ssl_support = 0; |
| 68 | } |
| 69 | |
| 70 | return [ |
| 71 | 'curl_version' => $curl['version'], |
| 72 | 'is_ssl' => $ssl_support, |
| 73 | ]; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 |