Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| DiagnosticsWidgetRenderer | |
100.00% |
17 / 17 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| supports | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| render | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Grid\Widget; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\Model\PermissionContext; |
| 12 | use App\Core\Engine\Domain\Model\RelationGridMetadata; |
| 13 | use App\Core\Engine\Domain\Model\WidgetMetadata; |
| 14 | use App\Modules\About\Application\Service\SystemDiagnosticsServiceInterface; |
| 15 | use Psr\Http\Message\ServerRequestInterface; |
| 16 | use Twig\Environment as TwigEnvironment; |
| 17 | |
| 18 | /** |
| 19 | * Diagnostics Widget Renderer. |
| 20 | * |
| 21 | * Renders system requirements and security audit diagnostics in a Gridstack widget tile. |
| 22 | * |
| 23 | * @package App\Core\Grid\Widget |
| 24 | */ |
| 25 | final readonly class DiagnosticsWidgetRenderer implements WidgetRendererInterface |
| 26 | { |
| 27 | /** |
| 28 | * DiagnosticsWidgetRenderer constructor. |
| 29 | * |
| 30 | * @param SystemDiagnosticsServiceInterface $diagnosticsService System diagnostics inspector. |
| 31 | * @param TwigEnvironment $twig Twig template environment. |
| 32 | */ |
| 33 | public function __construct( |
| 34 | private SystemDiagnosticsServiceInterface $diagnosticsService, |
| 35 | private TwigEnvironment $twig, |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | /** {@inheritdoc} */ |
| 40 | public function supports(WidgetMetadata $widget): bool |
| 41 | { |
| 42 | return $widget->category === 'diagnostics' |
| 43 | || $widget->name === 'system_diagnostics' |
| 44 | || $widget->name === 'security_audit' |
| 45 | || $widget->handlerClass === self::class |
| 46 | || $widget->handlerClass === 'App\\Core\\Grid\\Widget\\DiagnosticsWidgetRenderer'; |
| 47 | } |
| 48 | |
| 49 | /** {@inheritdoc} */ |
| 50 | public function render( |
| 51 | RelationGridMetadata $relation, |
| 52 | ServerRequestInterface $request, |
| 53 | PermissionContext $context |
| 54 | ): string { |
| 55 | $section = (string) ($relation->widgetParams['section'] ?? 'server'); |
| 56 | $queryParams = $request->getQueryParams(); |
| 57 | $forceRefresh = !empty($queryParams['force_refresh']) || !empty($queryParams['refresh']); |
| 58 | $report = $this->diagnosticsService->runDiagnostics($section, $forceRefresh); |
| 59 | |
| 60 | $viewData = [ |
| 61 | 'relation' => $relation, |
| 62 | 'summary' => $report['summary'], |
| 63 | 'categories' => $report['categories'], |
| 64 | 'activeTab' => $section, |
| 65 | ]; |
| 66 | |
| 67 | return $this->twig->render('engine/partials/widget_diagnostics.twig', $viewData); |
| 68 | } |
| 69 | } |