@@ -12,39 +12,39 @@ |
||
12 | 12 | |
13 | 13 | // Ensure we've initialized Composer |
14 | 14 | if (!file_exists(APPROOT . '/vendor/autoload.php')) { |
15 | - header('HTTP/1.1 500 Internal Server Error', null, 500); |
|
16 | - header('Content-Type: application/json; charset=utf-8'); |
|
17 | - |
|
18 | - echo \json_encode( |
|
19 | - [ |
|
20 | - 'code' => 500, |
|
21 | - 'message' => 'Composer is not set up properly, please run "composer install".', |
|
22 | - 'error' => true, |
|
23 | - ] |
|
24 | - ); |
|
25 | - |
|
26 | - exit; |
|
15 | + header('HTTP/1.1 500 Internal Server Error', null, 500); |
|
16 | + header('Content-Type: application/json; charset=utf-8'); |
|
17 | + |
|
18 | + echo \json_encode( |
|
19 | + [ |
|
20 | + 'code' => 500, |
|
21 | + 'message' => 'Composer is not set up properly, please run "composer install".', |
|
22 | + 'error' => true, |
|
23 | + ] |
|
24 | + ); |
|
25 | + |
|
26 | + exit; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | require APPROOT . '/vendor/autoload.php'; |
30 | 30 | |
31 | 31 | try { |
32 | - (new \Joomla\StatsServer\Kernel\WebKernel())->run(); |
|
32 | + (new \Joomla\StatsServer\Kernel\WebKernel())->run(); |
|
33 | 33 | } catch (\Throwable $throwable) { |
34 | - error_log($throwable); |
|
35 | - |
|
36 | - if (!headers_sent()) { |
|
37 | - header('HTTP/1.1 500 Internal Server Error', null, 500); |
|
38 | - header('Content-Type: application/json; charset=utf-8'); |
|
39 | - } |
|
40 | - |
|
41 | - echo \json_encode( |
|
42 | - [ |
|
43 | - 'code' => $throwable->getCode(), |
|
44 | - 'message' => 'An error occurred while executing the application: ' . $throwable->getMessage(), |
|
45 | - 'error' => true, |
|
46 | - ] |
|
47 | - ); |
|
48 | - |
|
49 | - exit; |
|
34 | + error_log($throwable); |
|
35 | + |
|
36 | + if (!headers_sent()) { |
|
37 | + header('HTTP/1.1 500 Internal Server Error', null, 500); |
|
38 | + header('Content-Type: application/json; charset=utf-8'); |
|
39 | + } |
|
40 | + |
|
41 | + echo \json_encode( |
|
42 | + [ |
|
43 | + 'code' => $throwable->getCode(), |
|
44 | + 'message' => 'An error occurred while executing the application: ' . $throwable->getMessage(), |
|
45 | + 'error' => true, |
|
46 | + ] |
|
47 | + ); |
|
48 | + |
|
49 | + exit; |
|
50 | 50 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | \define('APPROOT', \dirname(__DIR__)); |
12 | 12 | |
13 | 13 | // Ensure we've initialized Composer |
14 | -if (!file_exists(APPROOT . '/vendor/autoload.php')) { |
|
14 | +if (!file_exists(APPROOT.'/vendor/autoload.php')) { |
|
15 | 15 | header('HTTP/1.1 500 Internal Server Error', null, 500); |
16 | 16 | header('Content-Type: application/json; charset=utf-8'); |
17 | 17 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | exit; |
27 | 27 | } |
28 | 28 | |
29 | -require APPROOT . '/vendor/autoload.php'; |
|
29 | +require APPROOT.'/vendor/autoload.php'; |
|
30 | 30 | |
31 | 31 | try { |
32 | 32 | (new \Joomla\StatsServer\Kernel\WebKernel())->run(); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | echo \json_encode( |
42 | 42 | [ |
43 | 43 | 'code' => $throwable->getCode(), |
44 | - 'message' => 'An error occurred while executing the application: ' . $throwable->getMessage(), |
|
44 | + 'message' => 'An error occurred while executing the application: '.$throwable->getMessage(), |
|
45 | 45 | 'error' => true, |
46 | 46 | ] |
47 | 47 | ); |
@@ -17,384 +17,384 @@ |
||
17 | 17 | */ |
18 | 18 | class StatsJsonView extends JsonView |
19 | 19 | { |
20 | - /** |
|
21 | - * Flag if the response should return the raw data. |
|
22 | - * |
|
23 | - * @var boolean |
|
24 | - */ |
|
25 | - private $authorizedRaw = false; |
|
26 | - |
|
27 | - /** |
|
28 | - * Array holding the valid data sources. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $dataSources = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version']; |
|
33 | - |
|
34 | - /** |
|
35 | - * Flag if the response should return the recently updated data. |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - private $recent = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * Statistics repository. |
|
43 | - * |
|
44 | - * @var StatisticsRepository |
|
45 | - */ |
|
46 | - private $repository; |
|
47 | - |
|
48 | - /** |
|
49 | - * The data source to return. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $source = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * The timeframe to return. |
|
57 | - * |
|
58 | - * @var integer |
|
59 | - */ |
|
60 | - private $timeframe = 0; |
|
61 | - |
|
62 | - /** |
|
63 | - * Count of the number of items. |
|
64 | - * |
|
65 | - * @var integer |
|
66 | - */ |
|
67 | - private $totalItems = 0; |
|
68 | - |
|
69 | - /** |
|
70 | - * Instantiate the view. |
|
71 | - * |
|
72 | - * @param StatisticsRepository $repository Statistics repository. |
|
73 | - */ |
|
74 | - public function __construct(StatisticsRepository $repository) |
|
75 | - { |
|
76 | - $this->repository = $repository; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Set whether the raw data should be returned. |
|
81 | - * |
|
82 | - * @param bool $authorizedRaw Flag if the response should return the raw data. |
|
83 | - * |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function isAuthorizedRaw(bool $authorizedRaw): void |
|
87 | - { |
|
88 | - $this->authorizedRaw = $authorizedRaw; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Set whether the recently updated data should be returned. |
|
93 | - * |
|
94 | - * @param bool $recent Flag if the response should return the recently updated data. |
|
95 | - * |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public function isRecent(bool $recent): void |
|
99 | - { |
|
100 | - $this->recent = $recent; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Method to render the view. |
|
105 | - * |
|
106 | - * @return string The rendered view. |
|
107 | - */ |
|
108 | - public function render() |
|
109 | - { |
|
110 | - if ($this->timeframe > 0) { |
|
111 | - $items = $this->repository->getTimeframeUpdatedItems($this->timeframe, $this->source); |
|
112 | - } elseif ($this->recent) { |
|
113 | - $items = $this->repository->getRecentlyUpdatedItems(); |
|
114 | - } else { |
|
115 | - $items = $this->repository->getItems($this->source); |
|
116 | - } |
|
117 | - |
|
118 | - if ($this->source) { |
|
119 | - return $this->processSingleSource($items); |
|
120 | - } |
|
121 | - |
|
122 | - $php_version = []; |
|
123 | - $db_type = []; |
|
124 | - $db_version = []; |
|
125 | - $cms_version = []; |
|
126 | - $server_os = []; |
|
127 | - $cms_php_version = []; |
|
128 | - $db_type_version = []; |
|
129 | - |
|
130 | - // If we have the entire database, we have to loop within each group to put it all together |
|
131 | - foreach ($items as $group) { |
|
132 | - $this->totalItems = 0; |
|
133 | - |
|
134 | - foreach ($group as $item) { |
|
135 | - foreach ($this->dataSources as $source) { |
|
136 | - switch ($source) { |
|
137 | - case 'server_os': |
|
138 | - if (isset($item[$source]) && $item[$source] !== null) { |
|
139 | - // Special case, if the server is empty then change the key to "unknown" |
|
140 | - if (empty($item[$source])) { |
|
141 | - $item[$source] = 'unknown'; |
|
142 | - } |
|
143 | - |
|
144 | - ${$source}[$item[$source]] = $item['count']; |
|
145 | - |
|
146 | - $this->totalItems += $item['count']; |
|
147 | - } |
|
148 | - |
|
149 | - break; |
|
150 | - |
|
151 | - case 'cms_php_version': |
|
152 | - if ( |
|
153 | - (isset($item['cms_version']) && $item['cms_version'] !== null) |
|
154 | - && (isset($item['php_version']) && $item['php_version'] !== null) |
|
155 | - ) { |
|
156 | - $index = $item['cms_version'] . ' - ' . $item['php_version']; |
|
157 | - $cms_php_version[$index] = $item['count']; |
|
158 | - |
|
159 | - $this->totalItems += $item['count']; |
|
160 | - } |
|
161 | - |
|
162 | - break; |
|
163 | - |
|
164 | - case 'db_type_version': |
|
165 | - if ( |
|
166 | - (isset($item['db_type']) && $item['db_type'] !== null) |
|
167 | - && (isset($item['db_version']) && $item['db_version'] !== null) |
|
168 | - ) { |
|
169 | - $index = $item['db_type'] . ' - ' . $item['db_version']; |
|
170 | - $db_type_version[$index] = $item['count']; |
|
171 | - |
|
172 | - $this->totalItems += $item['count']; |
|
173 | - } |
|
174 | - |
|
175 | - break; |
|
176 | - |
|
177 | - default: |
|
178 | - if (isset($item[$source]) && $item[$source] !== null) { |
|
179 | - ${$source}[$item[$source]] = $item['count']; |
|
180 | - $this->totalItems += $item['count']; |
|
181 | - } |
|
182 | - |
|
183 | - break; |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - $data = [ |
|
190 | - 'php_version' => $php_version, |
|
191 | - 'db_type' => $db_type, |
|
192 | - 'db_version' => $db_version, |
|
193 | - 'cms_version' => $cms_version, |
|
194 | - 'server_os' => $server_os, |
|
195 | - 'cms_php_version' => $cms_php_version, |
|
196 | - 'db_type_version' => $db_type_version, |
|
197 | - ]; |
|
198 | - |
|
199 | - $responseData = $this->buildResponseData($data); |
|
200 | - |
|
201 | - $responseData['total'] = $this->totalItems; |
|
202 | - |
|
203 | - $this->addData('data', $responseData); |
|
204 | - |
|
205 | - return parent::render(); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Set the data source. |
|
210 | - * |
|
211 | - * @param string $source Data source to return. |
|
212 | - * |
|
213 | - * @return void |
|
214 | - */ |
|
215 | - public function setSource(string $source): void |
|
216 | - { |
|
217 | - $this->source = $source; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Set the data source. |
|
222 | - * |
|
223 | - * @param string $timeframe Timeframe to return. |
|
224 | - * |
|
225 | - * @return void |
|
226 | - */ |
|
227 | - public function setTimeframe(int $timeframe): void |
|
228 | - { |
|
229 | - $this->timeframe = $timeframe; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Process the raw data into the response data format. |
|
234 | - * |
|
235 | - * @param array $data The raw data array. |
|
236 | - * |
|
237 | - * @return array |
|
238 | - */ |
|
239 | - private function buildResponseData(array $data): array |
|
240 | - { |
|
241 | - $responseData = []; |
|
242 | - |
|
243 | - foreach ($data as $key => $value) { |
|
244 | - foreach ($value as $name => $count) { |
|
245 | - if ($name) { |
|
246 | - $responseData[$key][] = [ |
|
247 | - 'name' => $name, |
|
248 | - 'count' => $count, |
|
249 | - ]; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - unset($data); |
|
255 | - |
|
256 | - if (!$this->authorizedRaw) { |
|
257 | - $responseData = $this->sanitizeData($responseData); |
|
258 | - } |
|
259 | - |
|
260 | - return $responseData; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Process the response for a single data source. |
|
265 | - * |
|
266 | - * @param array $items The source items to process. |
|
267 | - * |
|
268 | - * @return string The rendered view. |
|
269 | - */ |
|
270 | - private function processSingleSource(array $items): string |
|
271 | - { |
|
272 | - $data = [ |
|
273 | - ${$this->source} = [], |
|
274 | - ]; |
|
275 | - |
|
276 | - $this->totalItems = 0; |
|
277 | - |
|
278 | - foreach ($items as $item) { |
|
279 | - switch ($this->source) { |
|
280 | - case 'server_os': |
|
281 | - // Special case, if the server is empty then change the key to "unknown" |
|
282 | - if (empty(trim($item[$this->source]))) { |
|
283 | - $item[$this->source] = 'unknown'; |
|
284 | - } |
|
285 | - |
|
286 | - $data[$this->source][$item[$this->source]] = $item['count']; |
|
287 | - break; |
|
288 | - |
|
289 | - case 'cms_php_version': |
|
290 | - $index = $item['cms_version'] . ' - ' . $item['php_version']; |
|
291 | - $data[$this->source][$index] = $item['count']; |
|
292 | - break; |
|
293 | - |
|
294 | - case 'db_type_version': |
|
295 | - $index = $item['db_type'] . ' - ' . $item['db_version']; |
|
296 | - $data[$this->source][$index] = $item['count']; |
|
297 | - break; |
|
298 | - |
|
299 | - default: |
|
300 | - $data[$this->source][$item[$this->source]] = $item['count']; |
|
301 | - break; |
|
302 | - } |
|
303 | - |
|
304 | - $this->totalItems += $item['count']; |
|
305 | - } |
|
306 | - |
|
307 | - $responseData = $this->buildResponseData($data); |
|
308 | - |
|
309 | - $responseData['total'] = $this->totalItems; |
|
310 | - |
|
311 | - $this->addData('data', $responseData); |
|
312 | - |
|
313 | - return parent::render(); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Sanitize the response data into summarized groups. |
|
318 | - * |
|
319 | - * @param array $responseData The response data to sanitize. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - private function sanitizeData(array $responseData): array |
|
324 | - { |
|
325 | - foreach ($responseData as $key => $dataGroup) { |
|
326 | - switch ($key) { |
|
327 | - case 'php_version': |
|
328 | - case 'db_version': |
|
329 | - case 'cms_version': |
|
330 | - // We're going to group by minor version branch here and convert to a percentage |
|
331 | - $counts = []; |
|
332 | - |
|
333 | - foreach ($dataGroup as $row) { |
|
334 | - $exploded = explode('.', $row['name']); |
|
335 | - $version = $exploded[0] . '.' . ($exploded[1] ?? '0'); |
|
336 | - |
|
337 | - // If the container does not exist, add it |
|
338 | - if (!isset($counts[$version])) { |
|
339 | - $counts[$version] = 0; |
|
340 | - } |
|
341 | - |
|
342 | - $counts[$version] += $row['count']; |
|
343 | - } |
|
344 | - |
|
345 | - $sanitizedData = []; |
|
346 | - |
|
347 | - foreach ($counts as $version => $count) { |
|
348 | - $sanitizedData[$version] = round(($count / $this->totalItems) * 100, 2); |
|
349 | - } |
|
350 | - |
|
351 | - $responseData[$key] = $sanitizedData; |
|
352 | - |
|
353 | - break; |
|
354 | - |
|
355 | - case 'server_os': |
|
356 | - // We're going to group by operating system here |
|
357 | - $counts = []; |
|
358 | - |
|
359 | - foreach ($dataGroup as $row) { |
|
360 | - $fullOs = explode(' ', $row['name']); |
|
361 | - $os = $fullOs[0]; |
|
362 | - |
|
363 | - // If the container does not exist, add it |
|
364 | - if (!isset($counts[$os])) { |
|
365 | - $counts[$os] = 0; |
|
366 | - } |
|
367 | - |
|
368 | - $counts[$os] += $row['count']; |
|
369 | - } |
|
20 | + /** |
|
21 | + * Flag if the response should return the raw data. |
|
22 | + * |
|
23 | + * @var boolean |
|
24 | + */ |
|
25 | + private $authorizedRaw = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * Array holding the valid data sources. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $dataSources = ['php_version', 'db_type', 'db_version', 'cms_version', 'server_os', 'cms_php_version', 'db_type_version']; |
|
33 | + |
|
34 | + /** |
|
35 | + * Flag if the response should return the recently updated data. |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + private $recent = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * Statistics repository. |
|
43 | + * |
|
44 | + * @var StatisticsRepository |
|
45 | + */ |
|
46 | + private $repository; |
|
47 | + |
|
48 | + /** |
|
49 | + * The data source to return. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $source = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * The timeframe to return. |
|
57 | + * |
|
58 | + * @var integer |
|
59 | + */ |
|
60 | + private $timeframe = 0; |
|
61 | + |
|
62 | + /** |
|
63 | + * Count of the number of items. |
|
64 | + * |
|
65 | + * @var integer |
|
66 | + */ |
|
67 | + private $totalItems = 0; |
|
68 | + |
|
69 | + /** |
|
70 | + * Instantiate the view. |
|
71 | + * |
|
72 | + * @param StatisticsRepository $repository Statistics repository. |
|
73 | + */ |
|
74 | + public function __construct(StatisticsRepository $repository) |
|
75 | + { |
|
76 | + $this->repository = $repository; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Set whether the raw data should be returned. |
|
81 | + * |
|
82 | + * @param bool $authorizedRaw Flag if the response should return the raw data. |
|
83 | + * |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function isAuthorizedRaw(bool $authorizedRaw): void |
|
87 | + { |
|
88 | + $this->authorizedRaw = $authorizedRaw; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Set whether the recently updated data should be returned. |
|
93 | + * |
|
94 | + * @param bool $recent Flag if the response should return the recently updated data. |
|
95 | + * |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public function isRecent(bool $recent): void |
|
99 | + { |
|
100 | + $this->recent = $recent; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Method to render the view. |
|
105 | + * |
|
106 | + * @return string The rendered view. |
|
107 | + */ |
|
108 | + public function render() |
|
109 | + { |
|
110 | + if ($this->timeframe > 0) { |
|
111 | + $items = $this->repository->getTimeframeUpdatedItems($this->timeframe, $this->source); |
|
112 | + } elseif ($this->recent) { |
|
113 | + $items = $this->repository->getRecentlyUpdatedItems(); |
|
114 | + } else { |
|
115 | + $items = $this->repository->getItems($this->source); |
|
116 | + } |
|
117 | + |
|
118 | + if ($this->source) { |
|
119 | + return $this->processSingleSource($items); |
|
120 | + } |
|
121 | + |
|
122 | + $php_version = []; |
|
123 | + $db_type = []; |
|
124 | + $db_version = []; |
|
125 | + $cms_version = []; |
|
126 | + $server_os = []; |
|
127 | + $cms_php_version = []; |
|
128 | + $db_type_version = []; |
|
129 | + |
|
130 | + // If we have the entire database, we have to loop within each group to put it all together |
|
131 | + foreach ($items as $group) { |
|
132 | + $this->totalItems = 0; |
|
133 | + |
|
134 | + foreach ($group as $item) { |
|
135 | + foreach ($this->dataSources as $source) { |
|
136 | + switch ($source) { |
|
137 | + case 'server_os': |
|
138 | + if (isset($item[$source]) && $item[$source] !== null) { |
|
139 | + // Special case, if the server is empty then change the key to "unknown" |
|
140 | + if (empty($item[$source])) { |
|
141 | + $item[$source] = 'unknown'; |
|
142 | + } |
|
143 | + |
|
144 | + ${$source}[$item[$source]] = $item['count']; |
|
145 | + |
|
146 | + $this->totalItems += $item['count']; |
|
147 | + } |
|
148 | + |
|
149 | + break; |
|
150 | + |
|
151 | + case 'cms_php_version': |
|
152 | + if ( |
|
153 | + (isset($item['cms_version']) && $item['cms_version'] !== null) |
|
154 | + && (isset($item['php_version']) && $item['php_version'] !== null) |
|
155 | + ) { |
|
156 | + $index = $item['cms_version'] . ' - ' . $item['php_version']; |
|
157 | + $cms_php_version[$index] = $item['count']; |
|
158 | + |
|
159 | + $this->totalItems += $item['count']; |
|
160 | + } |
|
161 | + |
|
162 | + break; |
|
163 | + |
|
164 | + case 'db_type_version': |
|
165 | + if ( |
|
166 | + (isset($item['db_type']) && $item['db_type'] !== null) |
|
167 | + && (isset($item['db_version']) && $item['db_version'] !== null) |
|
168 | + ) { |
|
169 | + $index = $item['db_type'] . ' - ' . $item['db_version']; |
|
170 | + $db_type_version[$index] = $item['count']; |
|
171 | + |
|
172 | + $this->totalItems += $item['count']; |
|
173 | + } |
|
174 | + |
|
175 | + break; |
|
176 | + |
|
177 | + default: |
|
178 | + if (isset($item[$source]) && $item[$source] !== null) { |
|
179 | + ${$source}[$item[$source]] = $item['count']; |
|
180 | + $this->totalItems += $item['count']; |
|
181 | + } |
|
182 | + |
|
183 | + break; |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + $data = [ |
|
190 | + 'php_version' => $php_version, |
|
191 | + 'db_type' => $db_type, |
|
192 | + 'db_version' => $db_version, |
|
193 | + 'cms_version' => $cms_version, |
|
194 | + 'server_os' => $server_os, |
|
195 | + 'cms_php_version' => $cms_php_version, |
|
196 | + 'db_type_version' => $db_type_version, |
|
197 | + ]; |
|
198 | + |
|
199 | + $responseData = $this->buildResponseData($data); |
|
200 | + |
|
201 | + $responseData['total'] = $this->totalItems; |
|
202 | + |
|
203 | + $this->addData('data', $responseData); |
|
204 | + |
|
205 | + return parent::render(); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Set the data source. |
|
210 | + * |
|
211 | + * @param string $source Data source to return. |
|
212 | + * |
|
213 | + * @return void |
|
214 | + */ |
|
215 | + public function setSource(string $source): void |
|
216 | + { |
|
217 | + $this->source = $source; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Set the data source. |
|
222 | + * |
|
223 | + * @param string $timeframe Timeframe to return. |
|
224 | + * |
|
225 | + * @return void |
|
226 | + */ |
|
227 | + public function setTimeframe(int $timeframe): void |
|
228 | + { |
|
229 | + $this->timeframe = $timeframe; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Process the raw data into the response data format. |
|
234 | + * |
|
235 | + * @param array $data The raw data array. |
|
236 | + * |
|
237 | + * @return array |
|
238 | + */ |
|
239 | + private function buildResponseData(array $data): array |
|
240 | + { |
|
241 | + $responseData = []; |
|
242 | + |
|
243 | + foreach ($data as $key => $value) { |
|
244 | + foreach ($value as $name => $count) { |
|
245 | + if ($name) { |
|
246 | + $responseData[$key][] = [ |
|
247 | + 'name' => $name, |
|
248 | + 'count' => $count, |
|
249 | + ]; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + unset($data); |
|
255 | + |
|
256 | + if (!$this->authorizedRaw) { |
|
257 | + $responseData = $this->sanitizeData($responseData); |
|
258 | + } |
|
259 | + |
|
260 | + return $responseData; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Process the response for a single data source. |
|
265 | + * |
|
266 | + * @param array $items The source items to process. |
|
267 | + * |
|
268 | + * @return string The rendered view. |
|
269 | + */ |
|
270 | + private function processSingleSource(array $items): string |
|
271 | + { |
|
272 | + $data = [ |
|
273 | + ${$this->source} = [], |
|
274 | + ]; |
|
275 | + |
|
276 | + $this->totalItems = 0; |
|
277 | + |
|
278 | + foreach ($items as $item) { |
|
279 | + switch ($this->source) { |
|
280 | + case 'server_os': |
|
281 | + // Special case, if the server is empty then change the key to "unknown" |
|
282 | + if (empty(trim($item[$this->source]))) { |
|
283 | + $item[$this->source] = 'unknown'; |
|
284 | + } |
|
285 | + |
|
286 | + $data[$this->source][$item[$this->source]] = $item['count']; |
|
287 | + break; |
|
288 | + |
|
289 | + case 'cms_php_version': |
|
290 | + $index = $item['cms_version'] . ' - ' . $item['php_version']; |
|
291 | + $data[$this->source][$index] = $item['count']; |
|
292 | + break; |
|
293 | + |
|
294 | + case 'db_type_version': |
|
295 | + $index = $item['db_type'] . ' - ' . $item['db_version']; |
|
296 | + $data[$this->source][$index] = $item['count']; |
|
297 | + break; |
|
298 | + |
|
299 | + default: |
|
300 | + $data[$this->source][$item[$this->source]] = $item['count']; |
|
301 | + break; |
|
302 | + } |
|
303 | + |
|
304 | + $this->totalItems += $item['count']; |
|
305 | + } |
|
306 | + |
|
307 | + $responseData = $this->buildResponseData($data); |
|
308 | + |
|
309 | + $responseData['total'] = $this->totalItems; |
|
310 | + |
|
311 | + $this->addData('data', $responseData); |
|
312 | + |
|
313 | + return parent::render(); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Sanitize the response data into summarized groups. |
|
318 | + * |
|
319 | + * @param array $responseData The response data to sanitize. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + private function sanitizeData(array $responseData): array |
|
324 | + { |
|
325 | + foreach ($responseData as $key => $dataGroup) { |
|
326 | + switch ($key) { |
|
327 | + case 'php_version': |
|
328 | + case 'db_version': |
|
329 | + case 'cms_version': |
|
330 | + // We're going to group by minor version branch here and convert to a percentage |
|
331 | + $counts = []; |
|
332 | + |
|
333 | + foreach ($dataGroup as $row) { |
|
334 | + $exploded = explode('.', $row['name']); |
|
335 | + $version = $exploded[0] . '.' . ($exploded[1] ?? '0'); |
|
336 | + |
|
337 | + // If the container does not exist, add it |
|
338 | + if (!isset($counts[$version])) { |
|
339 | + $counts[$version] = 0; |
|
340 | + } |
|
341 | + |
|
342 | + $counts[$version] += $row['count']; |
|
343 | + } |
|
344 | + |
|
345 | + $sanitizedData = []; |
|
346 | + |
|
347 | + foreach ($counts as $version => $count) { |
|
348 | + $sanitizedData[$version] = round(($count / $this->totalItems) * 100, 2); |
|
349 | + } |
|
350 | + |
|
351 | + $responseData[$key] = $sanitizedData; |
|
352 | + |
|
353 | + break; |
|
354 | + |
|
355 | + case 'server_os': |
|
356 | + // We're going to group by operating system here |
|
357 | + $counts = []; |
|
358 | + |
|
359 | + foreach ($dataGroup as $row) { |
|
360 | + $fullOs = explode(' ', $row['name']); |
|
361 | + $os = $fullOs[0]; |
|
362 | + |
|
363 | + // If the container does not exist, add it |
|
364 | + if (!isset($counts[$os])) { |
|
365 | + $counts[$os] = 0; |
|
366 | + } |
|
367 | + |
|
368 | + $counts[$os] += $row['count']; |
|
369 | + } |
|
370 | 370 | |
371 | - $sanitizedData = []; |
|
371 | + $sanitizedData = []; |
|
372 | 372 | |
373 | - foreach ($counts as $os => $count) { |
|
374 | - $sanitizedData[$os] = round(($count / $this->totalItems) * 100, 2); |
|
375 | - } |
|
373 | + foreach ($counts as $os => $count) { |
|
374 | + $sanitizedData[$os] = round(($count / $this->totalItems) * 100, 2); |
|
375 | + } |
|
376 | 376 | |
377 | - $responseData[$key] = $sanitizedData; |
|
377 | + $responseData[$key] = $sanitizedData; |
|
378 | 378 | |
379 | - break; |
|
379 | + break; |
|
380 | 380 | |
381 | - case 'db_type': |
|
382 | - case 'cms_php_version': |
|
383 | - case 'db_type_version': |
|
384 | - default: |
|
385 | - // For now, group by the object name and figure out the percentages |
|
386 | - $sanitizedData = []; |
|
381 | + case 'db_type': |
|
382 | + case 'cms_php_version': |
|
383 | + case 'db_type_version': |
|
384 | + default: |
|
385 | + // For now, group by the object name and figure out the percentages |
|
386 | + $sanitizedData = []; |
|
387 | 387 | |
388 | - foreach ($dataGroup as $row) { |
|
389 | - $sanitizedData[$row['name']] = round(($row['count'] / $this->totalItems) * 100, 2); |
|
390 | - } |
|
388 | + foreach ($dataGroup as $row) { |
|
389 | + $sanitizedData[$row['name']] = round(($row['count'] / $this->totalItems) * 100, 2); |
|
390 | + } |
|
391 | 391 | |
392 | - $responseData[$key] = $sanitizedData; |
|
392 | + $responseData[$key] = $sanitizedData; |
|
393 | 393 | |
394 | - break; |
|
395 | - } |
|
396 | - } |
|
394 | + break; |
|
395 | + } |
|
396 | + } |
|
397 | 397 | |
398 | - return $responseData; |
|
399 | - } |
|
398 | + return $responseData; |
|
399 | + } |
|
400 | 400 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | (isset($item['cms_version']) && $item['cms_version'] !== null) |
154 | 154 | && (isset($item['php_version']) && $item['php_version'] !== null) |
155 | 155 | ) { |
156 | - $index = $item['cms_version'] . ' - ' . $item['php_version']; |
|
156 | + $index = $item['cms_version'].' - '.$item['php_version']; |
|
157 | 157 | $cms_php_version[$index] = $item['count']; |
158 | 158 | |
159 | 159 | $this->totalItems += $item['count']; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | (isset($item['db_type']) && $item['db_type'] !== null) |
167 | 167 | && (isset($item['db_version']) && $item['db_version'] !== null) |
168 | 168 | ) { |
169 | - $index = $item['db_type'] . ' - ' . $item['db_version']; |
|
169 | + $index = $item['db_type'].' - '.$item['db_version']; |
|
170 | 170 | $db_type_version[$index] = $item['count']; |
171 | 171 | |
172 | 172 | $this->totalItems += $item['count']; |
@@ -287,12 +287,12 @@ discard block |
||
287 | 287 | break; |
288 | 288 | |
289 | 289 | case 'cms_php_version': |
290 | - $index = $item['cms_version'] . ' - ' . $item['php_version']; |
|
290 | + $index = $item['cms_version'].' - '.$item['php_version']; |
|
291 | 291 | $data[$this->source][$index] = $item['count']; |
292 | 292 | break; |
293 | 293 | |
294 | 294 | case 'db_type_version': |
295 | - $index = $item['db_type'] . ' - ' . $item['db_version']; |
|
295 | + $index = $item['db_type'].' - '.$item['db_version']; |
|
296 | 296 | $data[$this->source][$index] = $item['count']; |
297 | 297 | break; |
298 | 298 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | |
333 | 333 | foreach ($dataGroup as $row) { |
334 | 334 | $exploded = explode('.', $row['name']); |
335 | - $version = $exploded[0] . '.' . ($exploded[1] ?? '0'); |
|
335 | + $version = $exploded[0].'.'.($exploded[1] ?? '0'); |
|
336 | 336 | |
337 | 337 | // If the container does not exist, add it |
338 | 338 | if (!isset($counts[$version])) { |
@@ -19,32 +19,32 @@ |
||
19 | 19 | */ |
20 | 20 | class GitHubServiceProvider implements ServiceProviderInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Registers the service provider with a DI container. |
|
24 | - * |
|
25 | - * @param Container $container The DI container. |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function register(Container $container): void |
|
30 | - { |
|
31 | - $container->alias('github', BaseGithub::class) |
|
32 | - ->alias(GitHub::class, BaseGithub::class) |
|
33 | - ->share(BaseGithub::class, [$this, 'getGithubService']); |
|
34 | - } |
|
22 | + /** |
|
23 | + * Registers the service provider with a DI container. |
|
24 | + * |
|
25 | + * @param Container $container The DI container. |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function register(Container $container): void |
|
30 | + { |
|
31 | + $container->alias('github', BaseGithub::class) |
|
32 | + ->alias(GitHub::class, BaseGithub::class) |
|
33 | + ->share(BaseGithub::class, [$this, 'getGithubService']); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the `github` service |
|
38 | - * |
|
39 | - * @param Container $container The DI container. |
|
40 | - * |
|
41 | - * @return GitHub |
|
42 | - */ |
|
43 | - public function getGithubService(Container $container): GitHub |
|
44 | - { |
|
45 | - /** @var \Joomla\Registry\Registry $config */ |
|
46 | - $config = $container->get('config'); |
|
36 | + /** |
|
37 | + * Get the `github` service |
|
38 | + * |
|
39 | + * @param Container $container The DI container. |
|
40 | + * |
|
41 | + * @return GitHub |
|
42 | + */ |
|
43 | + public function getGithubService(Container $container): GitHub |
|
44 | + { |
|
45 | + /** @var \Joomla\Registry\Registry $config */ |
|
46 | + $config = $container->get('config'); |
|
47 | 47 | |
48 | - return new GitHub($config->extract('github')); |
|
49 | - } |
|
48 | + return new GitHub($config->extract('github')); |
|
49 | + } |
|
50 | 50 | } |
@@ -37,190 +37,190 @@ |
||
37 | 37 | */ |
38 | 38 | class ConsoleServiceProvider implements ServiceProviderInterface |
39 | 39 | { |
40 | - /** |
|
41 | - * Registers the service provider with a DI container. |
|
42 | - * |
|
43 | - * @param Container $container The DI container. |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function register(Container $container): void |
|
48 | - { |
|
49 | - $container->share(Application::class, [$this, 'getConsoleApplicationService']); |
|
50 | - |
|
51 | - /* |
|
40 | + /** |
|
41 | + * Registers the service provider with a DI container. |
|
42 | + * |
|
43 | + * @param Container $container The DI container. |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function register(Container $container): void |
|
48 | + { |
|
49 | + $container->share(Application::class, [$this, 'getConsoleApplicationService']); |
|
50 | + |
|
51 | + /* |
|
52 | 52 | * Application Helpers and Dependencies |
53 | 53 | */ |
54 | 54 | |
55 | - $container->alias(ContainerLoader::class, LoaderInterface::class) |
|
56 | - ->share(LoaderInterface::class, [$this, 'getCommandLoaderService']); |
|
55 | + $container->alias(ContainerLoader::class, LoaderInterface::class) |
|
56 | + ->share(LoaderInterface::class, [$this, 'getCommandLoaderService']); |
|
57 | 57 | |
58 | - /* |
|
58 | + /* |
|
59 | 59 | * Commands |
60 | 60 | */ |
61 | 61 | |
62 | - $container->share(DebugEventDispatcherCommand::class, [$this, 'getDebugEventDispatcherCommandService']); |
|
63 | - $container->share(DebugRouterCommand::class, [$this, 'getDebugRouterCommandService']); |
|
64 | - $container->share(MigrateCommand::class, [$this, 'getDatabaseMigrateCommandService']); |
|
65 | - $container->share(MigrationStatusCommand::class, [$this, 'getDatabaseMigrationStatusCommandService']); |
|
66 | - $container->share(FetchJoomlaTagsCommand::class, [$this, 'getFetchJoomlaTagsCommandService']); |
|
67 | - $container->share(FetchPhpTagsCommand::class, [$this, 'getFetchPhpTagsCommandService']); |
|
68 | - $container->share(SnapshotCommand::class, [$this, 'getSnapshotCommandService']); |
|
69 | - $container->share(SnapshotRecentlyUpdatedCommand::class, [$this, 'getSnapshotRecentlyUpdatedCommandService']); |
|
70 | - $container->share(UpdateCommand::class, [$this, 'getUpdateCommandService']); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get the LoaderInterface service |
|
75 | - * |
|
76 | - * @param Container $container The DI container. |
|
77 | - * |
|
78 | - * @return LoaderInterface |
|
79 | - */ |
|
80 | - public function getCommandLoaderService(Container $container): LoaderInterface |
|
81 | - { |
|
82 | - $mapping = [ |
|
83 | - DebugEventDispatcherCommand::getDefaultName() => DebugEventDispatcherCommand::class, |
|
84 | - DebugRouterCommand::getDefaultName() => DebugRouterCommand::class, |
|
85 | - MigrationStatusCommand::getDefaultName() => MigrationStatusCommand::class, |
|
86 | - MigrateCommand::getDefaultName() => MigrateCommand::class, |
|
87 | - FetchJoomlaTagsCommand::getDefaultName() => FetchJoomlaTagsCommand::class, |
|
88 | - FetchPhpTagsCommand::getDefaultName() => FetchPhpTagsCommand::class, |
|
89 | - SnapshotCommand::getDefaultName() => SnapshotCommand::class, |
|
90 | - SnapshotRecentlyUpdatedCommand::getDefaultName() => SnapshotRecentlyUpdatedCommand::class, |
|
91 | - UpdateCommand::getDefaultName() => UpdateCommand::class, |
|
92 | - ]; |
|
93 | - |
|
94 | - return new ContainerLoader($container, $mapping); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get the console Application service |
|
99 | - * |
|
100 | - * @param Container $container The DI container. |
|
101 | - * |
|
102 | - * @return Application |
|
103 | - */ |
|
104 | - public function getConsoleApplicationService(Container $container): Application |
|
105 | - { |
|
106 | - $application = new Application(new ArgvInput(), new ConsoleOutput(), $container->get('config')); |
|
107 | - |
|
108 | - $application->setCommandLoader($container->get(LoaderInterface::class)); |
|
109 | - $application->setDispatcher($container->get(DispatcherInterface::class)); |
|
110 | - $application->setLogger($container->get(LoggerInterface::class)); |
|
111 | - $application->setName('Joomla! Statistics Server'); |
|
112 | - |
|
113 | - return $application; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get the MigrateCommand service |
|
118 | - * |
|
119 | - * @param Container $container The DI container. |
|
120 | - * |
|
121 | - * @return MigrateCommand |
|
122 | - */ |
|
123 | - public function getDatabaseMigrateCommandService(Container $container): MigrateCommand |
|
124 | - { |
|
125 | - $command = new MigrateCommand($container->get(Migrations::class)); |
|
126 | - $command->setLogger($container->get(LoggerInterface::class)); |
|
127 | - |
|
128 | - return $command; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Get the MigrationStatusCommand service |
|
133 | - * |
|
134 | - * @param Container $container The DI container. |
|
135 | - * |
|
136 | - * @return MigrationStatusCommand |
|
137 | - */ |
|
138 | - public function getDatabaseMigrationStatusCommandService(Container $container): MigrationStatusCommand |
|
139 | - { |
|
140 | - return new MigrationStatusCommand($container->get(Migrations::class)); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Get the DebugEventDispatcherCommand service |
|
145 | - * |
|
146 | - * @param Container $container The DI container. |
|
147 | - * |
|
148 | - * @return DebugEventDispatcherCommand |
|
149 | - */ |
|
150 | - public function getDebugEventDispatcherCommandService(Container $container): DebugEventDispatcherCommand |
|
151 | - { |
|
152 | - return new DebugEventDispatcherCommand($container->get(DispatcherInterface::class)); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Get the DebugRouterCommand service |
|
157 | - * |
|
158 | - * @param Container $container The DI container. |
|
159 | - * |
|
160 | - * @return DebugRouterCommand |
|
161 | - */ |
|
162 | - public function getDebugRouterCommandService(Container $container): DebugRouterCommand |
|
163 | - { |
|
164 | - return new DebugRouterCommand($container->get(Router::class)); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get the FetchJoomlaTagsCommand service |
|
169 | - * |
|
170 | - * @param Container $container The DI container. |
|
171 | - * |
|
172 | - * @return FetchJoomlaTagsCommand |
|
173 | - */ |
|
174 | - public function getFetchJoomlaTagsCommandService(Container $container): FetchJoomlaTagsCommand |
|
175 | - { |
|
176 | - return new FetchJoomlaTagsCommand($container->get(GitHub::class), $container->get('filesystem.versions')); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Get the FetchPhpTagsCommand class service |
|
181 | - * |
|
182 | - * @param Container $container The DI container. |
|
183 | - * |
|
184 | - * @return FetchPhpTagsCommand |
|
185 | - */ |
|
186 | - public function getFetchPhpTagsCommandService(Container $container): FetchPhpTagsCommand |
|
187 | - { |
|
188 | - return new FetchPhpTagsCommand($container->get(GitHub::class), $container->get('filesystem.versions')); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the SnapshotCommand service |
|
193 | - * |
|
194 | - * @param Container $container The DI container. |
|
195 | - * |
|
196 | - * @return SnapshotCommand |
|
197 | - */ |
|
198 | - public function getSnapshotCommandService(Container $container): SnapshotCommand |
|
199 | - { |
|
200 | - return new SnapshotCommand($container->get(StatsJsonView::class), $container->get('filesystem.snapshot')); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get the SnapshotRecentlyUpdatedCommand service |
|
205 | - * |
|
206 | - * @param Container $container The DI container. |
|
207 | - * |
|
208 | - * @return SnapshotRecentlyUpdatedCommand |
|
209 | - */ |
|
210 | - public function getSnapshotRecentlyUpdatedCommandService(Container $container): SnapshotRecentlyUpdatedCommand |
|
211 | - { |
|
212 | - return new SnapshotRecentlyUpdatedCommand($container->get(StatsJsonView::class), $container->get('filesystem.snapshot')); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Get the UpdateCommand class service |
|
217 | - * |
|
218 | - * @param Container $container The DI container. |
|
219 | - * |
|
220 | - * @return UpdateCommand |
|
221 | - */ |
|
222 | - public function getUpdateCommandService(Container $container): UpdateCommand |
|
223 | - { |
|
224 | - return new UpdateCommand(); |
|
225 | - } |
|
62 | + $container->share(DebugEventDispatcherCommand::class, [$this, 'getDebugEventDispatcherCommandService']); |
|
63 | + $container->share(DebugRouterCommand::class, [$this, 'getDebugRouterCommandService']); |
|
64 | + $container->share(MigrateCommand::class, [$this, 'getDatabaseMigrateCommandService']); |
|
65 | + $container->share(MigrationStatusCommand::class, [$this, 'getDatabaseMigrationStatusCommandService']); |
|
66 | + $container->share(FetchJoomlaTagsCommand::class, [$this, 'getFetchJoomlaTagsCommandService']); |
|
67 | + $container->share(FetchPhpTagsCommand::class, [$this, 'getFetchPhpTagsCommandService']); |
|
68 | + $container->share(SnapshotCommand::class, [$this, 'getSnapshotCommandService']); |
|
69 | + $container->share(SnapshotRecentlyUpdatedCommand::class, [$this, 'getSnapshotRecentlyUpdatedCommandService']); |
|
70 | + $container->share(UpdateCommand::class, [$this, 'getUpdateCommandService']); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get the LoaderInterface service |
|
75 | + * |
|
76 | + * @param Container $container The DI container. |
|
77 | + * |
|
78 | + * @return LoaderInterface |
|
79 | + */ |
|
80 | + public function getCommandLoaderService(Container $container): LoaderInterface |
|
81 | + { |
|
82 | + $mapping = [ |
|
83 | + DebugEventDispatcherCommand::getDefaultName() => DebugEventDispatcherCommand::class, |
|
84 | + DebugRouterCommand::getDefaultName() => DebugRouterCommand::class, |
|
85 | + MigrationStatusCommand::getDefaultName() => MigrationStatusCommand::class, |
|
86 | + MigrateCommand::getDefaultName() => MigrateCommand::class, |
|
87 | + FetchJoomlaTagsCommand::getDefaultName() => FetchJoomlaTagsCommand::class, |
|
88 | + FetchPhpTagsCommand::getDefaultName() => FetchPhpTagsCommand::class, |
|
89 | + SnapshotCommand::getDefaultName() => SnapshotCommand::class, |
|
90 | + SnapshotRecentlyUpdatedCommand::getDefaultName() => SnapshotRecentlyUpdatedCommand::class, |
|
91 | + UpdateCommand::getDefaultName() => UpdateCommand::class, |
|
92 | + ]; |
|
93 | + |
|
94 | + return new ContainerLoader($container, $mapping); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get the console Application service |
|
99 | + * |
|
100 | + * @param Container $container The DI container. |
|
101 | + * |
|
102 | + * @return Application |
|
103 | + */ |
|
104 | + public function getConsoleApplicationService(Container $container): Application |
|
105 | + { |
|
106 | + $application = new Application(new ArgvInput(), new ConsoleOutput(), $container->get('config')); |
|
107 | + |
|
108 | + $application->setCommandLoader($container->get(LoaderInterface::class)); |
|
109 | + $application->setDispatcher($container->get(DispatcherInterface::class)); |
|
110 | + $application->setLogger($container->get(LoggerInterface::class)); |
|
111 | + $application->setName('Joomla! Statistics Server'); |
|
112 | + |
|
113 | + return $application; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get the MigrateCommand service |
|
118 | + * |
|
119 | + * @param Container $container The DI container. |
|
120 | + * |
|
121 | + * @return MigrateCommand |
|
122 | + */ |
|
123 | + public function getDatabaseMigrateCommandService(Container $container): MigrateCommand |
|
124 | + { |
|
125 | + $command = new MigrateCommand($container->get(Migrations::class)); |
|
126 | + $command->setLogger($container->get(LoggerInterface::class)); |
|
127 | + |
|
128 | + return $command; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Get the MigrationStatusCommand service |
|
133 | + * |
|
134 | + * @param Container $container The DI container. |
|
135 | + * |
|
136 | + * @return MigrationStatusCommand |
|
137 | + */ |
|
138 | + public function getDatabaseMigrationStatusCommandService(Container $container): MigrationStatusCommand |
|
139 | + { |
|
140 | + return new MigrationStatusCommand($container->get(Migrations::class)); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Get the DebugEventDispatcherCommand service |
|
145 | + * |
|
146 | + * @param Container $container The DI container. |
|
147 | + * |
|
148 | + * @return DebugEventDispatcherCommand |
|
149 | + */ |
|
150 | + public function getDebugEventDispatcherCommandService(Container $container): DebugEventDispatcherCommand |
|
151 | + { |
|
152 | + return new DebugEventDispatcherCommand($container->get(DispatcherInterface::class)); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Get the DebugRouterCommand service |
|
157 | + * |
|
158 | + * @param Container $container The DI container. |
|
159 | + * |
|
160 | + * @return DebugRouterCommand |
|
161 | + */ |
|
162 | + public function getDebugRouterCommandService(Container $container): DebugRouterCommand |
|
163 | + { |
|
164 | + return new DebugRouterCommand($container->get(Router::class)); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get the FetchJoomlaTagsCommand service |
|
169 | + * |
|
170 | + * @param Container $container The DI container. |
|
171 | + * |
|
172 | + * @return FetchJoomlaTagsCommand |
|
173 | + */ |
|
174 | + public function getFetchJoomlaTagsCommandService(Container $container): FetchJoomlaTagsCommand |
|
175 | + { |
|
176 | + return new FetchJoomlaTagsCommand($container->get(GitHub::class), $container->get('filesystem.versions')); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Get the FetchPhpTagsCommand class service |
|
181 | + * |
|
182 | + * @param Container $container The DI container. |
|
183 | + * |
|
184 | + * @return FetchPhpTagsCommand |
|
185 | + */ |
|
186 | + public function getFetchPhpTagsCommandService(Container $container): FetchPhpTagsCommand |
|
187 | + { |
|
188 | + return new FetchPhpTagsCommand($container->get(GitHub::class), $container->get('filesystem.versions')); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the SnapshotCommand service |
|
193 | + * |
|
194 | + * @param Container $container The DI container. |
|
195 | + * |
|
196 | + * @return SnapshotCommand |
|
197 | + */ |
|
198 | + public function getSnapshotCommandService(Container $container): SnapshotCommand |
|
199 | + { |
|
200 | + return new SnapshotCommand($container->get(StatsJsonView::class), $container->get('filesystem.snapshot')); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get the SnapshotRecentlyUpdatedCommand service |
|
205 | + * |
|
206 | + * @param Container $container The DI container. |
|
207 | + * |
|
208 | + * @return SnapshotRecentlyUpdatedCommand |
|
209 | + */ |
|
210 | + public function getSnapshotRecentlyUpdatedCommandService(Container $container): SnapshotRecentlyUpdatedCommand |
|
211 | + { |
|
212 | + return new SnapshotRecentlyUpdatedCommand($container->get(StatsJsonView::class), $container->get('filesystem.snapshot')); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Get the UpdateCommand class service |
|
217 | + * |
|
218 | + * @param Container $container The DI container. |
|
219 | + * |
|
220 | + * @return UpdateCommand |
|
221 | + */ |
|
222 | + public function getUpdateCommandService(Container $container): UpdateCommand |
|
223 | + { |
|
224 | + return new UpdateCommand(); |
|
225 | + } |
|
226 | 226 | } |
@@ -21,150 +21,150 @@ |
||
21 | 21 | */ |
22 | 22 | class MonologServiceProvider implements ServiceProviderInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Registers the service provider with a DI container. |
|
26 | - * |
|
27 | - * @param Container $container The DI container. |
|
28 | - * |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function register(Container $container): void |
|
32 | - { |
|
33 | - // Register the PSR-3 processor |
|
34 | - $container->share('monolog.processor.psr3', [$this, 'getMonologProcessorPsr3Service']); |
|
35 | - |
|
36 | - // Register the web processor |
|
37 | - $container->share('monolog.processor.web', [$this, 'getMonologProcessorWebService']); |
|
38 | - |
|
39 | - // Register the web application handler |
|
40 | - $container->share('monolog.handler.application', [$this, 'getMonologHandlerApplicationService']); |
|
41 | - |
|
42 | - // Register the database handler |
|
43 | - $container->share('monolog.handler.database', [$this, 'getMonologHandlerDatabaseService']); |
|
44 | - |
|
45 | - // Register the web application Logger |
|
46 | - $container->share('monolog.logger.application', [$this, 'getMonologLoggerApplicationService']); |
|
47 | - |
|
48 | - // Register the CLI application Logger |
|
49 | - $container->share('monolog.logger.cli', [$this, 'getMonologLoggerCliService']); |
|
50 | - |
|
51 | - // Register the database Logger |
|
52 | - $container->share('monolog.logger.database', [$this, 'getMonologLoggerDatabaseService']); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Get the `monolog.processor.psr3` service |
|
57 | - * |
|
58 | - * @param Container $container The DI container. |
|
59 | - * |
|
60 | - * @return PsrLogMessageProcessor |
|
61 | - */ |
|
62 | - public function getMonologProcessorPsr3Service(Container $container): PsrLogMessageProcessor |
|
63 | - { |
|
64 | - return new PsrLogMessageProcessor(); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Get the `monolog.processor.web` service |
|
69 | - * |
|
70 | - * @param Container $container The DI container. |
|
71 | - * |
|
72 | - * @return WebProcessor |
|
73 | - */ |
|
74 | - public function getMonologProcessorWebService(Container $container): WebProcessor |
|
75 | - { |
|
76 | - return new WebProcessor(); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Get the `monolog.handler.application` service |
|
81 | - * |
|
82 | - * @param Container $container The DI container. |
|
83 | - * |
|
84 | - * @return StreamHandler |
|
85 | - */ |
|
86 | - public function getMonologHandlerApplicationService(Container $container): StreamHandler |
|
87 | - { |
|
88 | - /** @var \Joomla\Registry\Registry $config */ |
|
89 | - $config = $container->get('config'); |
|
90 | - |
|
91 | - $level = strtoupper($config->get('log.application', $config->get('log.level', 'error'))); |
|
92 | - |
|
93 | - return new StreamHandler(APPROOT . '/logs/stats.log', \constant('\\Monolog\\Logger::' . $level)); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the `monolog.handler.database` service |
|
98 | - * |
|
99 | - * @param Container $container The DI container. |
|
100 | - * |
|
101 | - * @return StreamHandler |
|
102 | - */ |
|
103 | - public function getMonologHandlerDatabaseService(Container $container): StreamHandler |
|
104 | - { |
|
105 | - /** @var \Joomla\Registry\Registry $config */ |
|
106 | - $config = $container->get('config'); |
|
107 | - |
|
108 | - $level = strtoupper($config->get('log.database', $config->get('log.level', 'error'))); |
|
109 | - |
|
110 | - return new StreamHandler(APPROOT . '/logs/stats.log', \constant('\\Monolog\\Logger::' . $level)); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the `monolog.logger.application` service |
|
115 | - * |
|
116 | - * @param Container $container The DI container. |
|
117 | - * |
|
118 | - * @return Logger |
|
119 | - */ |
|
120 | - public function getMonologLoggerApplicationService(Container $container): Logger |
|
121 | - { |
|
122 | - return new Logger( |
|
123 | - 'Application', |
|
124 | - [ |
|
125 | - $container->get('monolog.handler.application'), |
|
126 | - ], |
|
127 | - [ |
|
128 | - $container->get('monolog.processor.web'), |
|
129 | - ] |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Get the `monolog.logger.cli` service |
|
135 | - * |
|
136 | - * @param Container $container The DI container. |
|
137 | - * |
|
138 | - * @return Logger |
|
139 | - */ |
|
140 | - public function getMonologLoggerCliService(Container $container): Logger |
|
141 | - { |
|
142 | - return new Logger( |
|
143 | - 'Application', |
|
144 | - [ |
|
145 | - $container->get('monolog.handler.application'), |
|
146 | - ] |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Get the `monolog.logger.database` service |
|
152 | - * |
|
153 | - * @param Container $container The DI container. |
|
154 | - * |
|
155 | - * @return Logger |
|
156 | - */ |
|
157 | - public function getMonologLoggerDatabaseService(Container $container): Logger |
|
158 | - { |
|
159 | - return new Logger( |
|
160 | - 'Application', |
|
161 | - [ |
|
162 | - $container->get('monolog.handler.database'), |
|
163 | - ], |
|
164 | - [ |
|
165 | - $container->get('monolog.processor.psr3'), |
|
166 | - $container->get('monolog.processor.web'), |
|
167 | - ] |
|
168 | - ); |
|
169 | - } |
|
24 | + /** |
|
25 | + * Registers the service provider with a DI container. |
|
26 | + * |
|
27 | + * @param Container $container The DI container. |
|
28 | + * |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function register(Container $container): void |
|
32 | + { |
|
33 | + // Register the PSR-3 processor |
|
34 | + $container->share('monolog.processor.psr3', [$this, 'getMonologProcessorPsr3Service']); |
|
35 | + |
|
36 | + // Register the web processor |
|
37 | + $container->share('monolog.processor.web', [$this, 'getMonologProcessorWebService']); |
|
38 | + |
|
39 | + // Register the web application handler |
|
40 | + $container->share('monolog.handler.application', [$this, 'getMonologHandlerApplicationService']); |
|
41 | + |
|
42 | + // Register the database handler |
|
43 | + $container->share('monolog.handler.database', [$this, 'getMonologHandlerDatabaseService']); |
|
44 | + |
|
45 | + // Register the web application Logger |
|
46 | + $container->share('monolog.logger.application', [$this, 'getMonologLoggerApplicationService']); |
|
47 | + |
|
48 | + // Register the CLI application Logger |
|
49 | + $container->share('monolog.logger.cli', [$this, 'getMonologLoggerCliService']); |
|
50 | + |
|
51 | + // Register the database Logger |
|
52 | + $container->share('monolog.logger.database', [$this, 'getMonologLoggerDatabaseService']); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Get the `monolog.processor.psr3` service |
|
57 | + * |
|
58 | + * @param Container $container The DI container. |
|
59 | + * |
|
60 | + * @return PsrLogMessageProcessor |
|
61 | + */ |
|
62 | + public function getMonologProcessorPsr3Service(Container $container): PsrLogMessageProcessor |
|
63 | + { |
|
64 | + return new PsrLogMessageProcessor(); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Get the `monolog.processor.web` service |
|
69 | + * |
|
70 | + * @param Container $container The DI container. |
|
71 | + * |
|
72 | + * @return WebProcessor |
|
73 | + */ |
|
74 | + public function getMonologProcessorWebService(Container $container): WebProcessor |
|
75 | + { |
|
76 | + return new WebProcessor(); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Get the `monolog.handler.application` service |
|
81 | + * |
|
82 | + * @param Container $container The DI container. |
|
83 | + * |
|
84 | + * @return StreamHandler |
|
85 | + */ |
|
86 | + public function getMonologHandlerApplicationService(Container $container): StreamHandler |
|
87 | + { |
|
88 | + /** @var \Joomla\Registry\Registry $config */ |
|
89 | + $config = $container->get('config'); |
|
90 | + |
|
91 | + $level = strtoupper($config->get('log.application', $config->get('log.level', 'error'))); |
|
92 | + |
|
93 | + return new StreamHandler(APPROOT . '/logs/stats.log', \constant('\\Monolog\\Logger::' . $level)); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the `monolog.handler.database` service |
|
98 | + * |
|
99 | + * @param Container $container The DI container. |
|
100 | + * |
|
101 | + * @return StreamHandler |
|
102 | + */ |
|
103 | + public function getMonologHandlerDatabaseService(Container $container): StreamHandler |
|
104 | + { |
|
105 | + /** @var \Joomla\Registry\Registry $config */ |
|
106 | + $config = $container->get('config'); |
|
107 | + |
|
108 | + $level = strtoupper($config->get('log.database', $config->get('log.level', 'error'))); |
|
109 | + |
|
110 | + return new StreamHandler(APPROOT . '/logs/stats.log', \constant('\\Monolog\\Logger::' . $level)); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the `monolog.logger.application` service |
|
115 | + * |
|
116 | + * @param Container $container The DI container. |
|
117 | + * |
|
118 | + * @return Logger |
|
119 | + */ |
|
120 | + public function getMonologLoggerApplicationService(Container $container): Logger |
|
121 | + { |
|
122 | + return new Logger( |
|
123 | + 'Application', |
|
124 | + [ |
|
125 | + $container->get('monolog.handler.application'), |
|
126 | + ], |
|
127 | + [ |
|
128 | + $container->get('monolog.processor.web'), |
|
129 | + ] |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Get the `monolog.logger.cli` service |
|
135 | + * |
|
136 | + * @param Container $container The DI container. |
|
137 | + * |
|
138 | + * @return Logger |
|
139 | + */ |
|
140 | + public function getMonologLoggerCliService(Container $container): Logger |
|
141 | + { |
|
142 | + return new Logger( |
|
143 | + 'Application', |
|
144 | + [ |
|
145 | + $container->get('monolog.handler.application'), |
|
146 | + ] |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Get the `monolog.logger.database` service |
|
152 | + * |
|
153 | + * @param Container $container The DI container. |
|
154 | + * |
|
155 | + * @return Logger |
|
156 | + */ |
|
157 | + public function getMonologLoggerDatabaseService(Container $container): Logger |
|
158 | + { |
|
159 | + return new Logger( |
|
160 | + 'Application', |
|
161 | + [ |
|
162 | + $container->get('monolog.handler.database'), |
|
163 | + ], |
|
164 | + [ |
|
165 | + $container->get('monolog.processor.psr3'), |
|
166 | + $container->get('monolog.processor.web'), |
|
167 | + ] |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | $level = strtoupper($config->get('log.application', $config->get('log.level', 'error'))); |
92 | 92 | |
93 | - return new StreamHandler(APPROOT . '/logs/stats.log', \constant('\\Monolog\\Logger::' . $level)); |
|
93 | + return new StreamHandler(APPROOT.'/logs/stats.log', \constant('\\Monolog\\Logger::'.$level)); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $level = strtoupper($config->get('log.database', $config->get('log.level', 'error'))); |
109 | 109 | |
110 | - return new StreamHandler(APPROOT . '/logs/stats.log', \constant('\\Monolog\\Logger::' . $level)); |
|
110 | + return new StreamHandler(APPROOT.'/logs/stats.log', \constant('\\Monolog\\Logger::'.$level)); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -19,53 +19,53 @@ |
||
19 | 19 | */ |
20 | 20 | class FlysystemServiceProvider implements ServiceProviderInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Registers the service provider with a DI container. |
|
24 | - * |
|
25 | - * @param Container $container The DI container. |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function register(Container $container): void |
|
30 | - { |
|
31 | - $container->share('filesystem.migrations', [$this, 'getMigrationsFilesystemService']); |
|
32 | - $container->share('filesystem.snapshot', [$this, 'getSnapshotFilesystemService']); |
|
33 | - $container->share('filesystem.versions', [$this, 'getVersionsFilesystemService']); |
|
34 | - } |
|
22 | + /** |
|
23 | + * Registers the service provider with a DI container. |
|
24 | + * |
|
25 | + * @param Container $container The DI container. |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function register(Container $container): void |
|
30 | + { |
|
31 | + $container->share('filesystem.migrations', [$this, 'getMigrationsFilesystemService']); |
|
32 | + $container->share('filesystem.snapshot', [$this, 'getSnapshotFilesystemService']); |
|
33 | + $container->share('filesystem.versions', [$this, 'getVersionsFilesystemService']); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the `filesystem.migrations` service |
|
38 | - * |
|
39 | - * @param Container $container The DI container. |
|
40 | - * |
|
41 | - * @return Filesystem |
|
42 | - */ |
|
43 | - public function getMigrationsFilesystemService(Container $container): Filesystem |
|
44 | - { |
|
45 | - return new Filesystem(new Local(APPROOT . '/etc/migrations')); |
|
46 | - } |
|
36 | + /** |
|
37 | + * Get the `filesystem.migrations` service |
|
38 | + * |
|
39 | + * @param Container $container The DI container. |
|
40 | + * |
|
41 | + * @return Filesystem |
|
42 | + */ |
|
43 | + public function getMigrationsFilesystemService(Container $container): Filesystem |
|
44 | + { |
|
45 | + return new Filesystem(new Local(APPROOT . '/etc/migrations')); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get the `filesystem.snapshot` service |
|
50 | - * |
|
51 | - * @param Container $container The DI container. |
|
52 | - * |
|
53 | - * @return Filesystem |
|
54 | - */ |
|
55 | - public function getSnapshotFilesystemService(Container $container): Filesystem |
|
56 | - { |
|
57 | - return new Filesystem(new Local(APPROOT . '/snapshots')); |
|
58 | - } |
|
48 | + /** |
|
49 | + * Get the `filesystem.snapshot` service |
|
50 | + * |
|
51 | + * @param Container $container The DI container. |
|
52 | + * |
|
53 | + * @return Filesystem |
|
54 | + */ |
|
55 | + public function getSnapshotFilesystemService(Container $container): Filesystem |
|
56 | + { |
|
57 | + return new Filesystem(new Local(APPROOT . '/snapshots')); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Get the `filesystem.versions` service |
|
62 | - * |
|
63 | - * @param Container $container The DI container. |
|
64 | - * |
|
65 | - * @return Filesystem |
|
66 | - */ |
|
67 | - public function getVersionsFilesystemService(Container $container): Filesystem |
|
68 | - { |
|
69 | - return new Filesystem(new Local(APPROOT . '/versions')); |
|
70 | - } |
|
60 | + /** |
|
61 | + * Get the `filesystem.versions` service |
|
62 | + * |
|
63 | + * @param Container $container The DI container. |
|
64 | + * |
|
65 | + * @return Filesystem |
|
66 | + */ |
|
67 | + public function getVersionsFilesystemService(Container $container): Filesystem |
|
68 | + { |
|
69 | + return new Filesystem(new Local(APPROOT . '/versions')); |
|
70 | + } |
|
71 | 71 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getMigrationsFilesystemService(Container $container): Filesystem |
44 | 44 | { |
45 | - return new Filesystem(new Local(APPROOT . '/etc/migrations')); |
|
45 | + return new Filesystem(new Local(APPROOT.'/etc/migrations')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function getSnapshotFilesystemService(Container $container): Filesystem |
56 | 56 | { |
57 | - return new Filesystem(new Local(APPROOT . '/snapshots')); |
|
57 | + return new Filesystem(new Local(APPROOT.'/snapshots')); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -66,6 +66,6 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getVersionsFilesystemService(Container $container): Filesystem |
68 | 68 | { |
69 | - return new Filesystem(new Local(APPROOT . '/versions')); |
|
69 | + return new Filesystem(new Local(APPROOT.'/versions')); |
|
70 | 70 | } |
71 | 71 | } |
@@ -33,192 +33,192 @@ |
||
33 | 33 | */ |
34 | 34 | class WebApplicationServiceProvider implements ServiceProviderInterface |
35 | 35 | { |
36 | - /** |
|
37 | - * Registers the service provider with a DI container. |
|
38 | - * |
|
39 | - * @param Container $container The DI container. |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function register(Container $container): void |
|
44 | - { |
|
45 | - $container->alias(WebApplication::class, AbstractWebApplication::class) |
|
46 | - ->share(AbstractWebApplication::class, [$this, 'getWebApplicationService']); |
|
47 | - |
|
48 | - /* |
|
36 | + /** |
|
37 | + * Registers the service provider with a DI container. |
|
38 | + * |
|
39 | + * @param Container $container The DI container. |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function register(Container $container): void |
|
44 | + { |
|
45 | + $container->alias(WebApplication::class, AbstractWebApplication::class) |
|
46 | + ->share(AbstractWebApplication::class, [$this, 'getWebApplicationService']); |
|
47 | + |
|
48 | + /* |
|
49 | 49 | * Application Class Dependencies |
50 | 50 | */ |
51 | 51 | |
52 | - $container->share(Input::class, [$this, 'getInputService']); |
|
53 | - $container->share(Router::class, [$this, 'getRouterService']); |
|
52 | + $container->share(Input::class, [$this, 'getInputService']); |
|
53 | + $container->share(Router::class, [$this, 'getRouterService']); |
|
54 | 54 | |
55 | - $container->alias(ContainerControllerResolver::class, ControllerResolverInterface::class) |
|
56 | - ->share(ControllerResolverInterface::class, [$this, 'getControllerResolverService']); |
|
55 | + $container->alias(ContainerControllerResolver::class, ControllerResolverInterface::class) |
|
56 | + ->share(ControllerResolverInterface::class, [$this, 'getControllerResolverService']); |
|
57 | 57 | |
58 | - $container->share(WebClient::class, [$this, 'getWebClientService']); |
|
58 | + $container->share(WebClient::class, [$this, 'getWebClientService']); |
|
59 | 59 | |
60 | - /* |
|
60 | + /* |
|
61 | 61 | * MVC Layer |
62 | 62 | */ |
63 | 63 | |
64 | - // Controllers |
|
65 | - $container->share(DisplayStatisticsController::class, [$this, 'getDisplayStatisticsControllerService']); |
|
66 | - $container->share(SubmitDataController::class, [$this, 'getSubmitDataControllerService']); |
|
67 | - |
|
68 | - // Views |
|
69 | - $container->share(StatsJsonView::class, [$this, 'getStatsJsonViewService']); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the controller resolver service |
|
74 | - * |
|
75 | - * @param Container $container The DI container. |
|
76 | - * |
|
77 | - * @return ControllerResolverInterface |
|
78 | - */ |
|
79 | - public function getControllerResolverService(Container $container): ControllerResolverInterface |
|
80 | - { |
|
81 | - return new ContainerControllerResolver($container); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get the DisplayControllerGet class service |
|
86 | - * |
|
87 | - * @param Container $container The DI container. |
|
88 | - * |
|
89 | - * @return DisplayStatisticsController |
|
90 | - */ |
|
91 | - public function getDisplayStatisticsControllerService(Container $container): DisplayStatisticsController |
|
92 | - { |
|
93 | - $controller = new DisplayStatisticsController( |
|
94 | - $container->get(StatsJsonView::class) |
|
95 | - ); |
|
96 | - |
|
97 | - $controller->setApplication($container->get(AbstractApplication::class)); |
|
98 | - $controller->setInput($container->get(Input::class)); |
|
99 | - |
|
100 | - return $controller; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get the Input class service |
|
105 | - * |
|
106 | - * @param Container $container The DI container. |
|
107 | - * |
|
108 | - * @return Input |
|
109 | - */ |
|
110 | - public function getInputService(Container $container): Input |
|
111 | - { |
|
112 | - return new Input($_REQUEST); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the router service |
|
117 | - * |
|
118 | - * @param Container $container The DI container. |
|
119 | - * |
|
120 | - * @return Router |
|
121 | - */ |
|
122 | - public function getRouterService(Container $container): Router |
|
123 | - { |
|
124 | - $router = new Router(); |
|
125 | - |
|
126 | - $router->get( |
|
127 | - '/', |
|
128 | - DisplayStatisticsController::class |
|
129 | - ); |
|
130 | - |
|
131 | - $router->post( |
|
132 | - '/submit', |
|
133 | - SubmitDataController::class |
|
134 | - ); |
|
135 | - |
|
136 | - $router->get( |
|
137 | - '/:source', |
|
138 | - DisplayStatisticsController::class, |
|
139 | - [ |
|
140 | - 'source' => '(' . implode('|', StatisticsRepository::ALLOWED_SOURCES) . ')', |
|
141 | - ] |
|
142 | - ); |
|
143 | - |
|
144 | - return $router; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get the StatsJsonView class service |
|
149 | - * |
|
150 | - * @param Container $container The DI container. |
|
151 | - * |
|
152 | - * @return StatsJsonView |
|
153 | - */ |
|
154 | - public function getStatsJsonViewService(Container $container): StatsJsonView |
|
155 | - { |
|
156 | - return new StatsJsonView( |
|
157 | - $container->get(StatisticsRepository::class) |
|
158 | - ); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Get the SubmitControllerCreate class service |
|
163 | - * |
|
164 | - * @param Container $container The DI container. |
|
165 | - * |
|
166 | - * @return SubmitDataController |
|
167 | - */ |
|
168 | - public function getSubmitDataControllerService(Container $container): SubmitDataController |
|
169 | - { |
|
170 | - $controller = new SubmitDataController( |
|
171 | - $container->get(StatisticsRepository::class), |
|
172 | - $container->get('filesystem.versions'), |
|
173 | - $container->get(InfluxdbRepository::class), |
|
174 | - ); |
|
175 | - |
|
176 | - $controller->setApplication($container->get(AbstractApplication::class)); |
|
177 | - $controller->setInput($container->get(Input::class)); |
|
178 | - |
|
179 | - return $controller; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Get the web application service |
|
184 | - * |
|
185 | - * @param Container $container The DI container. |
|
186 | - * |
|
187 | - * @return WebApplication |
|
188 | - */ |
|
189 | - public function getWebApplicationService(Container $container): WebApplication |
|
190 | - { |
|
191 | - $application = new WebApplication( |
|
192 | - $container->get(ControllerResolverInterface::class), |
|
193 | - $container->get(Router::class), |
|
194 | - $container->get(Input::class), |
|
195 | - $container->get('config'), |
|
196 | - $container->get(WebClient::class), |
|
197 | - new JsonResponse([]) |
|
198 | - ); |
|
199 | - |
|
200 | - // Inject extra services |
|
201 | - $application->setDispatcher($container->get(DispatcherInterface::class)); |
|
202 | - $application->setLogger($container->get(LoggerInterface::class)); |
|
203 | - |
|
204 | - return $application; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get the web client service |
|
209 | - * |
|
210 | - * @param Container $container The DI container. |
|
211 | - * |
|
212 | - * @return WebClient |
|
213 | - */ |
|
214 | - public function getWebClientService(Container $container): WebClient |
|
215 | - { |
|
216 | - /** @var Input $input */ |
|
217 | - $input = $container->get(Input::class); |
|
218 | - $userAgent = $input->server->getString('HTTP_USER_AGENT', ''); |
|
219 | - $acceptEncoding = $input->server->getString('HTTP_ACCEPT_ENCODING', ''); |
|
220 | - $acceptLanguage = $input->server->getString('HTTP_ACCEPT_LANGUAGE', ''); |
|
221 | - |
|
222 | - return new WebClient($userAgent, $acceptEncoding, $acceptLanguage); |
|
223 | - } |
|
64 | + // Controllers |
|
65 | + $container->share(DisplayStatisticsController::class, [$this, 'getDisplayStatisticsControllerService']); |
|
66 | + $container->share(SubmitDataController::class, [$this, 'getSubmitDataControllerService']); |
|
67 | + |
|
68 | + // Views |
|
69 | + $container->share(StatsJsonView::class, [$this, 'getStatsJsonViewService']); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the controller resolver service |
|
74 | + * |
|
75 | + * @param Container $container The DI container. |
|
76 | + * |
|
77 | + * @return ControllerResolverInterface |
|
78 | + */ |
|
79 | + public function getControllerResolverService(Container $container): ControllerResolverInterface |
|
80 | + { |
|
81 | + return new ContainerControllerResolver($container); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get the DisplayControllerGet class service |
|
86 | + * |
|
87 | + * @param Container $container The DI container. |
|
88 | + * |
|
89 | + * @return DisplayStatisticsController |
|
90 | + */ |
|
91 | + public function getDisplayStatisticsControllerService(Container $container): DisplayStatisticsController |
|
92 | + { |
|
93 | + $controller = new DisplayStatisticsController( |
|
94 | + $container->get(StatsJsonView::class) |
|
95 | + ); |
|
96 | + |
|
97 | + $controller->setApplication($container->get(AbstractApplication::class)); |
|
98 | + $controller->setInput($container->get(Input::class)); |
|
99 | + |
|
100 | + return $controller; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get the Input class service |
|
105 | + * |
|
106 | + * @param Container $container The DI container. |
|
107 | + * |
|
108 | + * @return Input |
|
109 | + */ |
|
110 | + public function getInputService(Container $container): Input |
|
111 | + { |
|
112 | + return new Input($_REQUEST); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the router service |
|
117 | + * |
|
118 | + * @param Container $container The DI container. |
|
119 | + * |
|
120 | + * @return Router |
|
121 | + */ |
|
122 | + public function getRouterService(Container $container): Router |
|
123 | + { |
|
124 | + $router = new Router(); |
|
125 | + |
|
126 | + $router->get( |
|
127 | + '/', |
|
128 | + DisplayStatisticsController::class |
|
129 | + ); |
|
130 | + |
|
131 | + $router->post( |
|
132 | + '/submit', |
|
133 | + SubmitDataController::class |
|
134 | + ); |
|
135 | + |
|
136 | + $router->get( |
|
137 | + '/:source', |
|
138 | + DisplayStatisticsController::class, |
|
139 | + [ |
|
140 | + 'source' => '(' . implode('|', StatisticsRepository::ALLOWED_SOURCES) . ')', |
|
141 | + ] |
|
142 | + ); |
|
143 | + |
|
144 | + return $router; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get the StatsJsonView class service |
|
149 | + * |
|
150 | + * @param Container $container The DI container. |
|
151 | + * |
|
152 | + * @return StatsJsonView |
|
153 | + */ |
|
154 | + public function getStatsJsonViewService(Container $container): StatsJsonView |
|
155 | + { |
|
156 | + return new StatsJsonView( |
|
157 | + $container->get(StatisticsRepository::class) |
|
158 | + ); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Get the SubmitControllerCreate class service |
|
163 | + * |
|
164 | + * @param Container $container The DI container. |
|
165 | + * |
|
166 | + * @return SubmitDataController |
|
167 | + */ |
|
168 | + public function getSubmitDataControllerService(Container $container): SubmitDataController |
|
169 | + { |
|
170 | + $controller = new SubmitDataController( |
|
171 | + $container->get(StatisticsRepository::class), |
|
172 | + $container->get('filesystem.versions'), |
|
173 | + $container->get(InfluxdbRepository::class), |
|
174 | + ); |
|
175 | + |
|
176 | + $controller->setApplication($container->get(AbstractApplication::class)); |
|
177 | + $controller->setInput($container->get(Input::class)); |
|
178 | + |
|
179 | + return $controller; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Get the web application service |
|
184 | + * |
|
185 | + * @param Container $container The DI container. |
|
186 | + * |
|
187 | + * @return WebApplication |
|
188 | + */ |
|
189 | + public function getWebApplicationService(Container $container): WebApplication |
|
190 | + { |
|
191 | + $application = new WebApplication( |
|
192 | + $container->get(ControllerResolverInterface::class), |
|
193 | + $container->get(Router::class), |
|
194 | + $container->get(Input::class), |
|
195 | + $container->get('config'), |
|
196 | + $container->get(WebClient::class), |
|
197 | + new JsonResponse([]) |
|
198 | + ); |
|
199 | + |
|
200 | + // Inject extra services |
|
201 | + $application->setDispatcher($container->get(DispatcherInterface::class)); |
|
202 | + $application->setLogger($container->get(LoggerInterface::class)); |
|
203 | + |
|
204 | + return $application; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get the web client service |
|
209 | + * |
|
210 | + * @param Container $container The DI container. |
|
211 | + * |
|
212 | + * @return WebClient |
|
213 | + */ |
|
214 | + public function getWebClientService(Container $container): WebClient |
|
215 | + { |
|
216 | + /** @var Input $input */ |
|
217 | + $input = $container->get(Input::class); |
|
218 | + $userAgent = $input->server->getString('HTTP_USER_AGENT', ''); |
|
219 | + $acceptEncoding = $input->server->getString('HTTP_ACCEPT_ENCODING', ''); |
|
220 | + $acceptLanguage = $input->server->getString('HTTP_ACCEPT_LANGUAGE', ''); |
|
221 | + |
|
222 | + return new WebClient($userAgent, $acceptEncoding, $acceptLanguage); |
|
223 | + } |
|
224 | 224 | } |
@@ -137,7 +137,7 @@ |
||
137 | 137 | '/:source', |
138 | 138 | DisplayStatisticsController::class, |
139 | 139 | [ |
140 | - 'source' => '(' . implode('|', StatisticsRepository::ALLOWED_SOURCES) . ')', |
|
140 | + 'source' => '('.implode('|', StatisticsRepository::ALLOWED_SOURCES).')', |
|
141 | 141 | ] |
142 | 142 | ); |
143 | 143 |
@@ -23,70 +23,70 @@ |
||
23 | 23 | */ |
24 | 24 | class EventServiceProvider implements ServiceProviderInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * Registers the service provider with a DI container. |
|
28 | - * |
|
29 | - * @param Container $container The DI container. |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function register(Container $container): void |
|
34 | - { |
|
35 | - $container->alias(Dispatcher::class, DispatcherInterface::class) |
|
36 | - ->share(DispatcherInterface::class, [$this, 'getDispatcherService']); |
|
26 | + /** |
|
27 | + * Registers the service provider with a DI container. |
|
28 | + * |
|
29 | + * @param Container $container The DI container. |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function register(Container $container): void |
|
34 | + { |
|
35 | + $container->alias(Dispatcher::class, DispatcherInterface::class) |
|
36 | + ->share(DispatcherInterface::class, [$this, 'getDispatcherService']); |
|
37 | 37 | |
38 | - $container->share(AnalyticsSubscriber::class, [$this, 'getAnalyticsSubscriberService']) |
|
39 | - ->tag('event.subscriber', [AnalyticsSubscriber::class]); |
|
38 | + $container->share(AnalyticsSubscriber::class, [$this, 'getAnalyticsSubscriberService']) |
|
39 | + ->tag('event.subscriber', [AnalyticsSubscriber::class]); |
|
40 | 40 | |
41 | - $container->share(ErrorSubscriber::class, [$this, 'getErrorSubscriberService']) |
|
42 | - ->tag('event.subscriber', [ErrorSubscriber::class]); |
|
43 | - } |
|
41 | + $container->share(ErrorSubscriber::class, [$this, 'getErrorSubscriberService']) |
|
42 | + ->tag('event.subscriber', [ErrorSubscriber::class]); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the AnalyticsSubscriber service |
|
47 | - * |
|
48 | - * @param Container $container The DI container. |
|
49 | - * |
|
50 | - * @return AnalyticsSubscriber |
|
51 | - */ |
|
52 | - public function getAnalyticsSubscriberService(Container $container): AnalyticsSubscriber |
|
53 | - { |
|
54 | - $subscriber = new AnalyticsSubscriber($container->get(Analytics::class)); |
|
55 | - $subscriber->setLogger($container->get(LoggerInterface::class)); |
|
45 | + /** |
|
46 | + * Get the AnalyticsSubscriber service |
|
47 | + * |
|
48 | + * @param Container $container The DI container. |
|
49 | + * |
|
50 | + * @return AnalyticsSubscriber |
|
51 | + */ |
|
52 | + public function getAnalyticsSubscriberService(Container $container): AnalyticsSubscriber |
|
53 | + { |
|
54 | + $subscriber = new AnalyticsSubscriber($container->get(Analytics::class)); |
|
55 | + $subscriber->setLogger($container->get(LoggerInterface::class)); |
|
56 | 56 | |
57 | - return $subscriber; |
|
58 | - } |
|
57 | + return $subscriber; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Get the DispatcherInterface service |
|
62 | - * |
|
63 | - * @param Container $container The DI container. |
|
64 | - * |
|
65 | - * @return DispatcherInterface |
|
66 | - */ |
|
67 | - public function getDispatcherService(Container $container): DispatcherInterface |
|
68 | - { |
|
69 | - $dispatcher = new Dispatcher(); |
|
60 | + /** |
|
61 | + * Get the DispatcherInterface service |
|
62 | + * |
|
63 | + * @param Container $container The DI container. |
|
64 | + * |
|
65 | + * @return DispatcherInterface |
|
66 | + */ |
|
67 | + public function getDispatcherService(Container $container): DispatcherInterface |
|
68 | + { |
|
69 | + $dispatcher = new Dispatcher(); |
|
70 | 70 | |
71 | - foreach ($container->getTagged('event.subscriber') as $subscriber) { |
|
72 | - $dispatcher->addSubscriber($subscriber); |
|
73 | - } |
|
71 | + foreach ($container->getTagged('event.subscriber') as $subscriber) { |
|
72 | + $dispatcher->addSubscriber($subscriber); |
|
73 | + } |
|
74 | 74 | |
75 | - return $dispatcher; |
|
76 | - } |
|
75 | + return $dispatcher; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get the ErrorSubscriber service |
|
80 | - * |
|
81 | - * @param Container $container The DI container. |
|
82 | - * |
|
83 | - * @return ErrorSubscriber |
|
84 | - */ |
|
85 | - public function getErrorSubscriberService(Container $container): ErrorSubscriber |
|
86 | - { |
|
87 | - $subscriber = new ErrorSubscriber(); |
|
88 | - $subscriber->setLogger($container->get(LoggerInterface::class)); |
|
78 | + /** |
|
79 | + * Get the ErrorSubscriber service |
|
80 | + * |
|
81 | + * @param Container $container The DI container. |
|
82 | + * |
|
83 | + * @return ErrorSubscriber |
|
84 | + */ |
|
85 | + public function getErrorSubscriberService(Container $container): ErrorSubscriber |
|
86 | + { |
|
87 | + $subscriber = new ErrorSubscriber(); |
|
88 | + $subscriber->setLogger($container->get(LoggerInterface::class)); |
|
89 | 89 | |
90 | - return $subscriber; |
|
91 | - } |
|
90 | + return $subscriber; |
|
91 | + } |
|
92 | 92 | } |
@@ -18,27 +18,27 @@ |
||
18 | 18 | */ |
19 | 19 | class AnalyticsServiceProvider implements ServiceProviderInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Registers the service provider with a DI container. |
|
23 | - * |
|
24 | - * @param Container $container The DI container. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register(Container $container): void |
|
29 | - { |
|
30 | - $container->share(Analytics::class, [$this, 'getAnalyticsService']); |
|
31 | - } |
|
21 | + /** |
|
22 | + * Registers the service provider with a DI container. |
|
23 | + * |
|
24 | + * @param Container $container The DI container. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register(Container $container): void |
|
29 | + { |
|
30 | + $container->share(Analytics::class, [$this, 'getAnalyticsService']); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Get the Analytics class service |
|
35 | - * |
|
36 | - * @param Container $container The DI container. |
|
37 | - * |
|
38 | - * @return Analytics |
|
39 | - */ |
|
40 | - public function getAnalyticsService(Container $container): Analytics |
|
41 | - { |
|
42 | - return new Analytics(true); |
|
43 | - } |
|
33 | + /** |
|
34 | + * Get the Analytics class service |
|
35 | + * |
|
36 | + * @param Container $container The DI container. |
|
37 | + * |
|
38 | + * @return Analytics |
|
39 | + */ |
|
40 | + public function getAnalyticsService(Container $container): Analytics |
|
41 | + { |
|
42 | + return new Analytics(true); |
|
43 | + } |
|
44 | 44 | } |