From 6082680e8655efcec0b255047b5b27064bf9fc3f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 26 Jan 2025 22:17:28 +0200 Subject: feat(controllers): Simplified non-standard method request logic --- controllers/meta.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'controllers') diff --git a/controllers/meta.php b/controllers/meta.php index 91a8ade..46550d3 100644 --- a/controllers/meta.php +++ b/controllers/meta.php @@ -8,16 +8,21 @@ function call_handler(string $name) { $TOKEN = (array_key_exists('token', $_COOKIE)) ? ($_COOKIE['token'] ?? "") : (""); -function request_handler() { - if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (array_key_exists('method', $_POST)) { - switch ($_POST['method']) { - case 'PUT': call_handler('Controller\on_put'); return; - case 'DELETE': call_handler('Controller\on_delete'); return; - case 'PATCH': call_handler('Controller\on_patch'); return; - } - } - call_handler('Controller\on_post'); +$METHOD = null; +if (array_key_exists('method', $_POST)) { + $METHOD = $_POST; +} +else if (array_key_exists('method', $_GET)) { + $METHOD = $_GET; +} + +if ($METHOD !== null) { + switch ($METHOD['method']) { + case 'PUT': call_handler('Controller\on_put'); break; + case 'DELETE': call_handler('Controller\on_delete'); break; + case 'PATCH': call_handler('Controller\on_patch'); break; } } -request_handler(); +else if ($_SERVER['REQUEST_METHOD'] === 'POST') { + call_handler('Controller\on_post'); +} -- cgit v1.2.3