From 6ec91935462b2c24daf89b68283e1c413887f2bd Mon Sep 17 00:00:00 2001 From: Dag Date: Wed, 7 Aug 2024 00:21:06 +0200 Subject: [PATCH] yuop (#4193) --- actions/ConnectivityAction.php | 4 ++-- actions/DetectAction.php | 2 +- actions/DisplayAction.php | 2 +- actions/FindfeedAction.php | 2 +- actions/FrontpageAction.php | 6 +++--- actions/HealthAction.php | 2 +- actions/ListAction.php | 2 +- lib/ActionInterface.php | 5 +---- lib/RssBridge.php | 5 +---- 9 files changed, 12 insertions(+), 18 deletions(-) diff --git a/actions/ConnectivityAction.php b/actions/ConnectivityAction.php index eb9edeb1..9732d0aa 100644 --- a/actions/ConnectivityAction.php +++ b/actions/ConnectivityAction.php @@ -19,7 +19,7 @@ class ConnectivityAction implements ActionInterface $this->bridgeFactory = new BridgeFactory(); } - public function execute(Request $request) + public function __invoke(Request $request): Response { if (!Debug::isEnabled()) { return new Response('This action is only available in debug mode!', 403); @@ -27,7 +27,7 @@ class ConnectivityAction implements ActionInterface $bridgeName = $request->get('bridge'); if (!$bridgeName) { - return render_template('connectivity.html.php'); + return new Response(render_template('connectivity.html.php')); } $bridgeClassName = $this->bridgeFactory->createBridgeClassName($bridgeName); if (!$bridgeClassName) { diff --git a/actions/DetectAction.php b/actions/DetectAction.php index 0c61f1b6..cebbc307 100644 --- a/actions/DetectAction.php +++ b/actions/DetectAction.php @@ -2,7 +2,7 @@ class DetectAction implements ActionInterface { - public function execute(Request $request) + public function __invoke(Request $request): Response { $url = $request->get('url'); $format = $request->get('format'); diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index d39d1812..aee47483 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -11,7 +11,7 @@ class DisplayAction implements ActionInterface $this->logger = RssBridge::getLogger(); } - public function execute(Request $request) + public function __invoke(Request $request): Response { $bridgeName = $request->get('bridge'); $format = $request->get('format'); diff --git a/actions/FindfeedAction.php b/actions/FindfeedAction.php index 94dc6b72..6654ca6d 100644 --- a/actions/FindfeedAction.php +++ b/actions/FindfeedAction.php @@ -7,7 +7,7 @@ */ class FindfeedAction implements ActionInterface { - public function execute(Request $request) + public function __invoke(Request $request): Response { $url = $request->get('url'); $format = $request->get('format'); diff --git a/actions/FrontpageAction.php b/actions/FrontpageAction.php index 32795c45..c72dfd57 100644 --- a/actions/FrontpageAction.php +++ b/actions/FrontpageAction.php @@ -2,7 +2,7 @@ final class FrontpageAction implements ActionInterface { - public function execute(Request $request) + public function __invoke(Request $request): Response { $messages = []; $activeBridges = 0; @@ -26,13 +26,13 @@ final class FrontpageAction implements ActionInterface } // todo: cache this renderered template? - return render(__DIR__ . '/../templates/frontpage.html.php', [ + 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), - ]); + ])); } } diff --git a/actions/HealthAction.php b/actions/HealthAction.php index a38879c2..13365a3c 100644 --- a/actions/HealthAction.php +++ b/actions/HealthAction.php @@ -4,7 +4,7 @@ declare(strict_types=1); class HealthAction implements ActionInterface { - public function execute(Request $request) + public function __invoke(Request $request): Response { $response = [ 'code' => 200, diff --git a/actions/ListAction.php b/actions/ListAction.php index 3d9cdd73..3dd8f441 100644 --- a/actions/ListAction.php +++ b/actions/ListAction.php @@ -2,7 +2,7 @@ class ListAction implements ActionInterface { - public function execute(Request $request) + public function __invoke(Request $request): Response { $list = new \stdClass(); $list->bridges = []; diff --git a/lib/ActionInterface.php b/lib/ActionInterface.php index c0ddcf9f..d2e1c709 100644 --- a/lib/ActionInterface.php +++ b/lib/ActionInterface.php @@ -2,8 +2,5 @@ interface ActionInterface { - /** - * @return string|Response - */ - public function execute(Request $request); + public function __invoke(Request $request): Response; } diff --git a/lib/RssBridge.php b/lib/RssBridge.php index 1bb5f5ea..87b11f52 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -100,11 +100,8 @@ final class RssBridge $className = '\\' . $actionName; $actionObject = new $className(); - $response = $actionObject->execute($request); + $response = $actionObject($request); - if (is_string($response)) { - $response = new Response($response); - } return $response; }