. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Contracts\UserInterface; use Fisharebest\Webtrees\Http\ViewResponseTrait; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Module\ModuleReportInterface; use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\Tree; use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; /** * Show all available reports. */ class ReportListPage implements RequestHandlerInterface { use ViewResponseTrait; /** * @var ModuleService */ private $module_service; /** * ReportEngineController constructor. * * @param ModuleService $module_service */ public function __construct(ModuleService $module_service) { $this->module_service = $module_service; } /** * A list of available reports. * * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree, new InvalidArgumentException()); $user = $request->getAttribute('user'); assert($user instanceof UserInterface, new InvalidArgumentException()); $reports = $this->module_service ->findByComponent(ModuleReportInterface::class, $tree, $user); $title = I18N::translate('Choose a report to run'); return $this->viewResponse('report-select-page', [ 'reports' => $reports, 'title' => $title, 'tree' => $tree, ]); } }