-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIndex.php
49 lines (40 loc) · 1.31 KB
/
Index.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
<?php declare(strict_types=1);
namespace Vendic\OhDear\Controller\Index;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\Json as JsonResult;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Vendic\OhDear\Api\CheckListInterface;
use Vendic\OhDear\Utils\Configuration;
/**
* @copyright Copyright (c) Vendic B.V https://vendic.nl/
*/
class Index implements HttpGetActionInterface
{
public function __construct(
private JsonFactory $jsonFactory,
private CheckListInterface $checkList,
private TimezoneInterface $timezone,
private Configuration $configuration
) {
}
public function execute() : JsonResult
{
$output = [];
$output['finishedAt'] = $this->now();
$output['checkResults'] = [];
foreach ($this->checkList->getChecks() as $check) {
if ($this->configuration->isCheckEnabled($check) === false) {
continue;
}
$output['checkResults'][] = $check->run()->toArray();
}
$json = $this->jsonFactory->create();
$json->setData($output);
return $json;
}
private function now(): int
{
return $this->timezone->date()->getTimestamp();
}
}