-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathStatusReport.php
More file actions
50 lines (43 loc) · 1.72 KB
/
StatusReport.php
File metadata and controls
50 lines (43 loc) · 1.72 KB
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
<?php
declare(strict_types=1);
namespace Lemming\Imageoptimizer\Report;
use Lemming\Imageoptimizer\OptimizeImageService;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Reports\Status;
use TYPO3\CMS\Reports\StatusProviderInterface;
readonly class StatusReport implements StatusProviderInterface
{
public function __construct(
private ExtensionConfiguration $extensionConfiguration
) {}
public function getLabel(): string
{
return 'Image Optimizer';
}
/**
* Determines if the needed binaries are found
*/
public function getStatus(): array
{
$configuration = $this->extensionConfiguration->get('imageoptimizer');
$extensions = ['jpg', 'png', 'gif', 'svg', 'webp'];
$status = [];
foreach ($extensions as $extension) {
$binary = escapeshellcmd($configuration[$extension . 'Binary']);
$binaryFound = is_string(CommandUtility::getCommand($binary));
$binaryUsed = ((bool) ($configuration[$extension . 'OnUpload'] ?? false) === true
|| (bool) ($configuration[$extension . 'OnProcessing'] ?? false) === true);
$status[$extension] = GeneralUtility::makeInstance(
Status::class,
'Binary ' . $binary,
$binaryFound ? 'Found' : OptimizeImageService::BINARY_NOT_FOUND,
$binaryUsed ? 'In use' : 'Not in use',
$binaryFound || $binaryUsed === false ? ContextualFeedbackSeverity::OK : ContextualFeedbackSeverity::ERROR
);
}
return $status;
}
}