This commit is contained in:
Dag 2024-08-07 00:21:06 +02:00 committed by GitHub
parent 401cc187b7
commit 6ec9193546
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 12 additions and 18 deletions

View File

@ -19,7 +19,7 @@ class ConnectivityAction implements ActionInterface
$this->bridgeFactory = new BridgeFactory(); $this->bridgeFactory = new BridgeFactory();
} }
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
if (!Debug::isEnabled()) { if (!Debug::isEnabled()) {
return new Response('This action is only available in debug mode!', 403); return new Response('This action is only available in debug mode!', 403);
@ -27,7 +27,7 @@ class ConnectivityAction implements ActionInterface
$bridgeName = $request->get('bridge'); $bridgeName = $request->get('bridge');
if (!$bridgeName) { if (!$bridgeName) {
return render_template('connectivity.html.php'); return new Response(render_template('connectivity.html.php'));
} }
$bridgeClassName = $this->bridgeFactory->createBridgeClassName($bridgeName); $bridgeClassName = $this->bridgeFactory->createBridgeClassName($bridgeName);
if (!$bridgeClassName) { if (!$bridgeClassName) {

View File

@ -2,7 +2,7 @@
class DetectAction implements ActionInterface class DetectAction implements ActionInterface
{ {
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
$url = $request->get('url'); $url = $request->get('url');
$format = $request->get('format'); $format = $request->get('format');

View File

@ -11,7 +11,7 @@ class DisplayAction implements ActionInterface
$this->logger = RssBridge::getLogger(); $this->logger = RssBridge::getLogger();
} }
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
$bridgeName = $request->get('bridge'); $bridgeName = $request->get('bridge');
$format = $request->get('format'); $format = $request->get('format');

View File

@ -7,7 +7,7 @@
*/ */
class FindfeedAction implements ActionInterface class FindfeedAction implements ActionInterface
{ {
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
$url = $request->get('url'); $url = $request->get('url');
$format = $request->get('format'); $format = $request->get('format');

View File

@ -2,7 +2,7 @@
final class FrontpageAction implements ActionInterface final class FrontpageAction implements ActionInterface
{ {
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
$messages = []; $messages = [];
$activeBridges = 0; $activeBridges = 0;
@ -26,13 +26,13 @@ final class FrontpageAction implements ActionInterface
} }
// todo: cache this renderered template? // todo: cache this renderered template?
return render(__DIR__ . '/../templates/frontpage.html.php', [ return new Response(render(__DIR__ . '/../templates/frontpage.html.php', [
'messages' => $messages, 'messages' => $messages,
'admin_email' => Configuration::getConfig('admin', 'email'), 'admin_email' => Configuration::getConfig('admin', 'email'),
'admin_telegram' => Configuration::getConfig('admin', 'telegram'), 'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
'bridges' => $body, 'bridges' => $body,
'active_bridges' => $activeBridges, 'active_bridges' => $activeBridges,
'total_bridges' => count($bridgeClassNames), 'total_bridges' => count($bridgeClassNames),
]); ]));
} }
} }

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
class HealthAction implements ActionInterface class HealthAction implements ActionInterface
{ {
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
$response = [ $response = [
'code' => 200, 'code' => 200,

View File

@ -2,7 +2,7 @@
class ListAction implements ActionInterface class ListAction implements ActionInterface
{ {
public function execute(Request $request) public function __invoke(Request $request): Response
{ {
$list = new \stdClass(); $list = new \stdClass();
$list->bridges = []; $list->bridges = [];

View File

@ -2,8 +2,5 @@
interface ActionInterface interface ActionInterface
{ {
/** public function __invoke(Request $request): Response;
* @return string|Response
*/
public function execute(Request $request);
} }

View File

@ -100,11 +100,8 @@ final class RssBridge
$className = '\\' . $actionName; $className = '\\' . $actionName;
$actionObject = new $className(); $actionObject = new $className();
$response = $actionObject->execute($request); $response = $actionObject($request);
if (is_string($response)) {
$response = new Response($response);
}
return $response; return $response;
} }