-
Notifications
You must be signed in to change notification settings - Fork 7
/
requirements_check.php
136 lines (114 loc) · 3.52 KB
/
requirements_check.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Requirements;
class RequirementsCheck
{
private $isCli;
private $lines = array();
public function __construct()
{
$this->isCli = php_sapi_name() === 'cli';
if (!$this->isCli) {
$this->lines[] = sprintf(
'<style type="text/css">%s %s %s %s</style>',
'html {font-family:verdana;}',
'div {margin: 0.5em 0 2em; padding: 1em;}',
'.ok {background:#dfffdf;border: 2px solid #0bo;color:#264409;}',
'.fail {background:#ffdfdf;border: 2px solid #b00;color:#8a1f11;}'
);
}
}
private function notify($type, $msg)
{
$this->lines[] = sprintf('<div class="%s">%s</div>', $type, $msg);
}
private function pass($msg)
{
if ($this->isCli) {
$this->lines[] = '[OK] '.$msg;
} else {
$this->notify('ok', $msg);
}
}
private function fail($msg)
{
if ($this->isCli) {
$this->lines[] = '[FAIL] '.$msg;
} else {
$this->notify('fail', $msg);
}
}
public function title($title)
{
if ($this->isCli) {
$this->lines[] = "\n$title\n".str_repeat('=', strlen($title));
} else {
$this->lines[] = "<h1>$title</h1>";
}
}
public function header($header)
{
if ($this->isCli) {
$this->lines[] = "\n$header\n".str_repeat('-', strlen($header));
} else {
$this->lines[] = "<h2>$header</h2>";
}
}
public function checkPhpVersion($version)
{
if (version_compare(phpversion(), $version, '>=')) {
$this->pass("You have PHP $version or greater");
} else {
$this->fail("You need PHP $version or greater");
}
}
public function checkExt($ext)
{
if (extension_loaded($ext)) {
$this->pass("You have the $ext extension installed");
} else {
$this->fail("You do not have the $ext extension installed");
}
}
public function checkCurl()
{
if (function_exists('curl_version')) {
$curlVersion = curl_version();
if (($curlVersion['features'] & CURL_VERSION_SSL)) {
$this->pass("cURL can send https requests [{$curlVersion['ssl_version']}]");
} else {
$this->pass('cURL cannot send https requests');
}
}
}
public function check64Bit()
{
if (PHP_INT_MAX === 9223372036854775807) {
$this->pass('You are running a 64-bit version of PHP');
} else {
$this->fail('You are not running a 64-bit version of PHP. You may run into issues when handling object properties and assigning values to integers that are greater than the largest possible 32 bit integer value');
}
}
public function phpInfo()
{
ob_start();
phpinfo(INFO_GENERAL);
$this->lines[]= ob_get_clean();
}
public function endCheck()
{
$text = implode("\n", $this->lines);
echo $this->isCli ? $text."\n\n" : "<!doctype html><html><body>$text</body></html>";
}
}
$check = new RequirementsCheck();
$check->title('eBay SDK for PHP Requirements Check');
$check->header('System Requirements');
$check->checkPhpVersion('5.5.0');
foreach (array('curl', 'libxml') as $ext) {
$check->checkExt($ext);
}
$check->checkCurl();
$check->check64Bit();
$check->title('PHP information');
$check->phpInfo();
$check->endCheck();