public static checkRequirements ( ) : array | ||
Résultat | array | list of each requirement, boolean true if met, string error message if not as value |
public static function checkRequirements()
{
$requirements = array();
// PHP Version
if (!defined('PHP_VERSION_ID')) {
$version = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]);
}
if (PHP_VERSION_ID < 50400) {
$requirements['PHP'] = 'Your PHP version, ' . PHP_VERSION . ', is too low. PHP version >= 5.4 is required.';
} else {
$requirements['PHP'] = true;
}
// Mcrypt Extension
if (!extension_loaded('mcrypt')) {
$requirements['Mcrypt'] = 'The Mcrypt PHP extension could not be found.';
} else {
$requirements['Mcrypt'] = true;
}
// OpenSSL Extension
if (!extension_loaded('openssl')) {
$requirements['OpenSSL'] = 'The OpenSSL PHP extension could not be found.';
} else {
$requirements['OpenSSL'] = true;
}
// JSON Extension
if (!extension_loaded('json')) {
$requirements['JSON'] = 'The JSON PHP extension could not be found.';
} else {
$requirements['JSON'] = true;
}
// cURL Extension
if (!extension_loaded('curl')) {
$requirements['cURL'] = 'The cURL PHP extension could not be found.';
} else {
$requirements['cURL'] = true;
$curl_version = curl_version();
$ssl_supported = $curl_version['features'] & CURL_VERSION_SSL;
if (!$ssl_supported) {
$requirements['cURL.SSL'] = 'The cURL PHP extension does not have SSL support.';
} else {
$requirements['cURL.SSL'] = true;
}
}
// Math
if (!extension_loaded('bcmath') && !extension_loaded('gmp')) {
$requirements['Math'] = 'Either the BC Math or GMP PHP extension is required. Neither could be found.';
} else {
$requirements['Math'] = true;
}
return $requirements;
}
public function testCheckRequirements() { $requirements = Util::checkRequirements(); // PHP Version if (!defined('PHP_VERSION_ID')) { $version = explode('.', PHP_VERSION); define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]); } if (PHP_VERSION_ID >= 50400) { $this->assertTrue($requirements['PHP']); } else { $this->assertTrue(is_string($requirements['PHP'])); } // Mcrypt Extension if (extension_loaded('mcrypt')) { $this->assertTrue($requirements['Mcrypt']); } else { $this->assertTrue(is_string($requirements['Mcrypt'])); } // OpenSSL Extension if (extension_loaded('openssl')) { $this->assertTrue($requirements['OpenSSL']); } else { $this->assertTrue(is_string($requirements['OpenSSL'])); } // JSON Extension if (extension_loaded('json')) { $this->assertTrue($requirements['JSON']); } else { $this->assertTrue(is_string($requirements['JSON'])); } // cURL Extension if (extension_loaded('curl')) { $this->assertTrue($requirements['cURL']); $curl_version = curl_version(); $ssl_supported = $curl_version['features'] & CURL_VERSION_SSL; if ($ssl_supported) { $this->assertTrue($requirements['cURL.SSL']); } else { $this->assertTrue(is_string($requirements['cURL.SSL'])); } } else { $this->assertTrue(is_string($requirements['cURL'])); $this->assertTrue(is_string($requirements['cURL'])); } // Math if (extension_loaded('bcmath') || extension_loaded('gmp')) { $this->assertTrue($requirements['Math']); } else { $this->assertTrue(is_string($requirements['Math'])); } }