added view to document

This commit is contained in:
Roman Hergenreder 2020-06-19 16:51:41 +02:00
parent 8d1c4836e7
commit d685952f17
4 changed files with 10 additions and 7 deletions

@ -9,9 +9,9 @@ namespace Documents {
use Views\LoginBody; use Views\LoginBody;
class Admin extends Document { class Admin extends Document {
public function __construct(User $user) { public function __construct(User $user, ?string $view = NULL) {
$body = $user->isLoggedIn() ? AdminDashboardBody::class : LoginBody::class; $body = $user->isLoggedIn() ? AdminDashboardBody::class : LoginBody::class;
parent::__construct($user, AdminHead::class, $body); parent::__construct($user, AdminHead::class, $body, $view);
} }
} }
} }

@ -7,8 +7,8 @@ namespace Documents {
use Elements\Document; use Elements\Document;
class Document404 extends Document { class Document404 extends Document {
public function __construct($user) { public function __construct($user, ?string $view = NULL) {
parent::__construct($user, Head404::class, Body404::class); parent::__construct($user, Head404::class, Body404::class, $view);
} }
} }
} }

@ -10,18 +10,21 @@ abstract class Document {
protected Body $body; protected Body $body;
protected User $user; protected User $user;
protected bool $databaseRequired; 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->head = new $headClass($this);
$this->body = new $bodyClass($this); $this->body = new $bodyClass($this);
$this->user = $user; $this->user = $user;
$this->databaseRequired = true; $this->databaseRequired = true;
$this->activeView = $view;
} }
public function getHead() { return $this->head; } public function getHead() { return $this->head; }
public function getBody() { return $this->body; } public function getBody() { return $this->body; }
public function getSQL() { return $this->user->getSQL(); } public function getSQL() { return $this->user->getSQL(); }
public function getUser() { return $this->user; } public function getUser() { return $this->user; }
public function getView() { return $this->activeView; }
protected function sendHeaders() { protected function sendHeaders() {
header("X-Frame-Options: DENY"); header("X-Frame-Options: DENY");

@ -99,9 +99,9 @@ if(isset($_GET["api"]) && is_string($_GET["api"])) {
$view = $route["extra"] ?? ""; $view = $route["extra"] ?? "";
$file = getClassPath($target); $file = getClassPath($target);
if(!file_exists($file) || !is_subclass_of($target, Document::class)) { if(!file_exists($file) || !is_subclass_of($target, Document::class)) {
$document = new Document404($user); $document = new Document404($user, $view);
} else { } else {
$document = new $target($user); $document = new $target($user, $view);
} }
$response = $document->getCode(); $response = $document->getCode();