1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\View; |
3
|
|
|
|
4
|
|
|
use Redaxscript\View; |
5
|
|
|
use function in_array; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* children class to create the system status |
9
|
|
|
* |
10
|
|
|
* @since 3.0.0 |
11
|
|
|
* |
12
|
|
|
* @package Redaxscript |
13
|
|
|
* @category View |
14
|
|
|
* @author Balázs Szilágyi |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
class SystemStatus extends ViewAbstract |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* render the view |
21
|
|
|
* |
22
|
|
|
* @since 3.0.0 |
23
|
|
|
* |
24
|
|
|
* @return string|null |
25
|
|
|
*/ |
26
|
|
|
|
27
|
3 |
|
public function render() : ?string |
28
|
|
|
{ |
29
|
3 |
|
$output = null; |
30
|
|
|
|
31
|
|
|
/* handle error */ |
32
|
|
|
|
33
|
3 |
|
$messageArray = $this->_validateError(); |
34
|
3 |
|
if ($messageArray) |
|
|
|
|
35
|
|
|
{ |
36
|
1 |
|
$output .= $this->_error( |
37
|
|
|
[ |
38
|
1 |
|
'message' => $messageArray |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/* handle warning */ |
43
|
|
|
|
44
|
3 |
|
$messageArray = $this->_validateWarning(); |
45
|
3 |
|
if ($messageArray) |
|
|
|
|
46
|
|
|
{ |
47
|
1 |
|
$output .= $this->_warning( |
48
|
|
|
[ |
49
|
1 |
|
'message' => $messageArray |
50
|
|
|
]); |
51
|
|
|
} |
52
|
3 |
|
return $output; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* validate the error |
57
|
|
|
* |
58
|
|
|
* @since 3.0.0 |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
|
63
|
5 |
|
protected function _validateError() : array |
64
|
|
|
{ |
65
|
5 |
|
$messageArray = []; |
66
|
5 |
|
if (!$this->_registry->get('dbStatus')) |
67
|
|
|
{ |
68
|
2 |
|
$messageArray[] = $this->_language->get('database_failed'); |
69
|
|
|
} |
70
|
5 |
|
if (!$this->_registry->get('phpStatus')) |
71
|
|
|
{ |
72
|
1 |
|
$messageArray[] = $this->_language->get('php_version_unsupported'); |
73
|
|
|
} |
74
|
5 |
|
if (!$this->_registry->get('sessionStatus')) |
75
|
|
|
{ |
76
|
1 |
|
$messageArray[] = $this->_language->get('session_disabled'); |
77
|
|
|
} |
78
|
5 |
|
if (!$this->_registry->get('driverArray')) |
79
|
|
|
{ |
80
|
1 |
|
$messageArray[] = $this->_language->get('pdo_driver_disabled'); |
81
|
|
|
} |
82
|
5 |
|
return $messageArray; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* validate the warning |
87
|
|
|
* |
88
|
|
|
* @since 3.0.0 |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
|
93
|
5 |
|
protected function _validateWarning() : array |
94
|
|
|
{ |
95
|
5 |
|
$messageArray = []; |
96
|
5 |
|
$phpOs = $this->_registry->get('phpOs'); |
97
|
|
|
$testOsArray = |
98
|
|
|
[ |
99
|
5 |
|
'linux', |
100
|
|
|
'windows' |
101
|
|
|
]; |
102
|
5 |
|
if (!in_array($phpOs, $testOsArray)) |
103
|
|
|
{ |
104
|
2 |
|
$messageArray[] = $this->_language->get('php_os_unsupported'); |
105
|
|
|
} |
106
|
5 |
|
return $messageArray; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* messenger factory |
111
|
|
|
* |
112
|
|
|
* @since 4.0.0 |
113
|
|
|
* |
114
|
|
|
* @return View\Helper\Messenger |
115
|
|
|
*/ |
116
|
|
|
|
117
|
2 |
|
protected function _messengerFactory() : View\Helper\Messenger |
118
|
|
|
{ |
119
|
2 |
|
return new View\Helper\Messenger($this->_registry); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* show the error |
124
|
|
|
* |
125
|
|
|
* @since 3.0.0 |
126
|
|
|
* |
127
|
|
|
* @param array $errorArray |
128
|
|
|
* |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
|
132
|
1 |
|
protected function _error(array $errorArray = []) : string |
133
|
|
|
{ |
134
|
1 |
|
$messenger = $this->_messengerFactory(); |
135
|
1 |
|
return $messenger->error($errorArray['message']); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* show the warning |
140
|
|
|
* |
141
|
|
|
* @since 3.0.0 |
142
|
|
|
* |
143
|
|
|
* @param array $warningArray |
144
|
|
|
* |
145
|
|
|
* @return string |
146
|
|
|
*/ |
147
|
|
|
|
148
|
1 |
|
protected function _warning(array $warningArray = []) : string |
149
|
|
|
{ |
150
|
1 |
|
$messenger = $this->_messengerFactory(); |
151
|
1 |
|
return $messenger->warning($warningArray['message']); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.