summaryrefslogtreecommitdiff
path: root/public/delete/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/delete/index.php')
-rw-r--r--public/delete/index.php20
1 files changed, 12 insertions, 8 deletions
diff --git a/public/delete/index.php b/public/delete/index.php
index 1b2484d..e07129a 100644
--- a/public/delete/index.php
+++ b/public/delete/index.php
@@ -3,25 +3,29 @@
declare(strict_types=1);
use DTS\BookmarkRepository;
-use DTS\Template;
use function DTS\Functions\respondAndExit;
+use function DTS\Functions\redirectAndExit;
require_once(__DIR__.'/../../autoload.php');
$config = require_once(__DIR__.'/../../config.php');
-$bookmarks = new BookmarkRepository($config['path_to_repository']);
+if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') !== 'POST') {
+ respondAndExit(405, 'Method Not Allowed');
+}
-$template = new Template($config['path_to_templates']);
+$id = filter_input(INPUT_POST, 'id');
-$id = filter_input(INPUT_GET, 'id') ?? filter_input(INPUT_POST, 'id') ?? null;
+$bookmarks = new BookmarkRepository($config['path_to_repository']);
$bookmark = $bookmarks->find($id);
-if ('POST' === filter_input(INPUT_SERVER, 'REQUEST_METHOD')) {
- $bookmarks->delete($bookmark);
+if ($bookmark === null) {
+ respondAndExit(404, 'Not Found');
}
-$html = $template->render('delete', compact('bookmark'));
+if (!$bookmarks->delete($bookmark)) {
+ respondAndExit(500, 'Internal Server Error');
+}
-respondAndExit(200, 'OK', $html);
+redirectAndExit('/');