|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Cundd\Rest\Controller; |
| 6 | + |
| 7 | +use Cundd\Rest\Documentation\HandlerDescriptor; |
| 8 | +use Cundd\Rest\Exception\InvalidConfigurationException; |
| 9 | +use Psr\Http\Message\ResponseInterface; |
| 10 | +use Psr\Http\Message\ServerRequestInterface; |
| 11 | +use TYPO3\CMS\Backend\Attribute\AsController; |
| 12 | +use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; |
| 13 | +use TYPO3\CMS\Core\Site\SiteFinder; |
| 14 | +use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
| 15 | + |
| 16 | +#[AsController] |
| 17 | +final class ReportController extends ActionController |
| 18 | +{ |
| 19 | + public function __construct( |
| 20 | + private readonly ModuleTemplateFactory $moduleTemplateFactory, |
| 21 | + private readonly SiteFinder $siteFinder, |
| 22 | + private readonly HandlerDescriptor $handlerDescriptor, |
| 23 | + ) { |
| 24 | + } |
| 25 | + |
| 26 | + public function handleRequest( |
| 27 | + ServerRequestInterface $request, |
| 28 | + ): ResponseInterface { |
| 29 | + $moduleTemplate = $this->moduleTemplateFactory->create($request); |
| 30 | + |
| 31 | + $information = []; |
| 32 | + foreach ($this->siteFinder->getAllSites() as $site) { |
| 33 | + $siteConfiguration = null; |
| 34 | + |
| 35 | + try { |
| 36 | + $siteConfiguration = $this->handlerDescriptor->getInformation($site); |
| 37 | + } catch (InvalidConfigurationException $e) { |
| 38 | + } |
| 39 | + |
| 40 | + if ($siteConfiguration) { |
| 41 | + $information = array_merge( |
| 42 | + $information, |
| 43 | + $siteConfiguration |
| 44 | + ); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + $moduleTemplate->assign('information', $information); |
| 49 | + |
| 50 | + return $moduleTemplate->renderResponse('HandlerReport'); |
| 51 | + } |
| 52 | +} |
0 commit comments