From d685952f1710f02789568807eb2de56e018a4f26 Mon Sep 17 00:00:00 2001 From: Roman Hergenreder Date: Fri, 19 Jun 2020 16:51:41 +0200 Subject: [PATCH] added view to document --- core/Documents/Admin.class.php | 4 ++-- core/Documents/Document404.class.php | 4 ++-- core/Elements/Document.class.php | 5 ++++- index.php | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/Documents/Admin.class.php b/core/Documents/Admin.class.php index c4fab3b..9389ccf 100644 --- a/core/Documents/Admin.class.php +++ b/core/Documents/Admin.class.php @@ -9,9 +9,9 @@ namespace Documents { use Views\LoginBody; class Admin extends Document { - public function __construct(User $user) { + public function __construct(User $user, ?string $view = NULL) { $body = $user->isLoggedIn() ? AdminDashboardBody::class : LoginBody::class; - parent::__construct($user, AdminHead::class, $body); + parent::__construct($user, AdminHead::class, $body, $view); } } } diff --git a/core/Documents/Document404.class.php b/core/Documents/Document404.class.php index 298b7f1..8ba2aa7 100644 --- a/core/Documents/Document404.class.php +++ b/core/Documents/Document404.class.php @@ -7,8 +7,8 @@ namespace Documents { use Elements\Document; class Document404 extends Document { - public function __construct($user) { - parent::__construct($user, Head404::class, Body404::class); + public function __construct($user, ?string $view = NULL) { + parent::__construct($user, Head404::class, Body404::class, $view); } } } diff --git a/core/Elements/Document.class.php b/core/Elements/Document.class.php index bbd3af8..41346bc 100644 --- a/core/Elements/Document.class.php +++ b/core/Elements/Document.class.php @@ -10,18 +10,21 @@ abstract class Document { protected Body $body; protected User $user; protected bool $databaseRequired; + private ?string $activeView; - public function __construct(User $user, $headClass, $bodyClass) { + public function __construct(User $user, $headClass, $bodyClass, ?string $view = NULL) { $this->head = new $headClass($this); $this->body = new $bodyClass($this); $this->user = $user; $this->databaseRequired = true; + $this->activeView = $view; } public function getHead() { return $this->head; } public function getBody() { return $this->body; } public function getSQL() { return $this->user->getSQL(); } public function getUser() { return $this->user; } + public function getView() { return $this->activeView; } protected function sendHeaders() { header("X-Frame-Options: DENY"); diff --git a/index.php b/index.php index c85e0b3..373a0b6 100644 --- a/index.php +++ b/index.php @@ -99,9 +99,9 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) { $view = $route["extra"] ?? ""; $file = getClassPath($target); if(!file_exists($file) || !is_subclass_of($target, Document::class)) { - $document = new Document404($user); + $document = new Document404($user, $view); } else { - $document = new $target($user); + $document = new $target($user, $view); } $response = $document->getCode();