rss-bridge/actions/FrontpageAction.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.3 KiB
PHP
Raw Normal View History

<?php
final class FrontpageAction implements ActionInterface
{
2024-08-07 01:21:06 +03:00
public function __invoke(Request $request): Response
{
$messages = [];
$activeBridges = 0;
$bridgeFactory = new BridgeFactory();
$bridgeClassNames = $bridgeFactory->getBridgeClassNames();
foreach ($bridgeFactory->getMissingEnabledBridges() as $missingEnabledBridge) {
$messages[] = [
'body' => sprintf('Warning : Bridge "%s" not found', $missingEnabledBridge),
'level' => 'warning'
];
}
$body = '';
foreach ($bridgeClassNames as $bridgeClassName) {
if ($bridgeFactory->isEnabled($bridgeClassName)) {
2024-01-25 20:20:02 +03:00
$body .= BridgeCard::render($bridgeClassName, $request);
$activeBridges++;
}
}
2024-01-25 15:03:00 +03:00
// todo: cache this renderered template?
2024-08-07 01:21:06 +03:00
return new Response(render(__DIR__ . '/../templates/frontpage.html.php', [
'messages' => $messages,
'admin_email' => Configuration::getConfig('admin', 'email'),
'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
'bridges' => $body,
'active_bridges' => $activeBridges,
'total_bridges' => count($bridgeClassNames),
2024-08-07 01:21:06 +03:00
]));
}
}