summaryrefslogtreecommitdiff
path: root/src/web/core/controller.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/core/controller.php')
-rw-r--r--src/web/core/controller.php65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/web/core/controller.php b/src/web/core/controller.php
deleted file mode 100644
index ca892e2..0000000
--- a/src/web/core/controller.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php /* Copyright (c) 2024 Freya Murphy */
-
-abstract class Controller extends Component {
-
- /**
- * Default index for a app, empty
- */
- public function index(): void {}
-
- /**
- * Redirectes to a link
- */
- public function redirect(string $link): void
- {
- header('Location: '. $link, true, 301);
- die();
- }
-
- /**
- * Lodas a view
- */
- protected function view(string $__name, array $data = array()): void
- {
- $__path = WEB_ROOT . '/_views/' . $__name . '.php';
- if (is_file($__path)) {
- extract($data);
- require($__path);
- }
- }
-
- /**
- * Loads a erorr page with a given
- * error code
- */
- protected function error(int $code): void
- {
- $error_controller = $this->load_controller('error');
- $error_controller->code($code);
- die();
- }
-
- /**
- * Returns HTTP POST information if POST request.
- * Returns 405 Method Not Allowed if not.
- *
- * If $key is specified, returns only that key. otherwise
- * returns HTTP 400 Bad Request;
- */
- protected function post_data(?string $key = NULL): array|string
- {
- // only post requests allowed
- if ($_SERVER['REQUEST_METHOD'] != 'POST')
- $this->error(405);
-
- // return entire $_POST array
- if (!$key)
- return $_POST;
-
- if (!isset($_POST[$key]))
- $this->error(400);
-
- return $_POST[$key];
- }
-
-}