web-base/core/Elements/Document.class.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2020-02-09 23:02:19 +01:00
<?php
namespace Elements;
2020-04-03 15:56:04 +02:00
use Objects\User;
2020-02-09 23:02:19 +01:00
abstract class Document {
2020-04-03 15:56:04 +02:00
protected Head $head;
protected Body $body;
protected User $user;
protected bool $databaseRequired;
2020-02-09 23:02:19 +01:00
2020-04-03 15:56:04 +02:00
public function __construct(User $user, $headClass, $bodyClass) {
2020-02-09 23:02:19 +01:00
$this->head = new $headClass($this);
$this->body = new $bodyClass($this);
$this->user = $user;
2020-04-02 21:39:02 +02:00
$this->databaseRequired = true;
2020-02-09 23:02:19 +01:00
}
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; }
protected function sendHeaders() {
header("X-Frame-Options: DENY");
}
public static function createSearchableDocument($documentClass, $user) {
return new $documentClass($user);
}
function getCode() {
2020-04-02 21:39:02 +02:00
if ($this->databaseRequired) {
2020-02-09 23:02:19 +01:00
$sql = $this->user->getSQL();
if (is_null($sql)) {
die("Database is not configured yet.");
2020-02-10 12:32:53 +01:00
} else if(!$sql->isConnected()) {
2020-02-09 23:02:19 +01:00
die("Database is not connected: " . $sql->getLastError());
}
}
$body = $this->body->getCode();
$head = $this->head->getCode();
$html = "<!DOCTYPE html>";
$html .= "<html>";
$html .= $head;
$html .= $body;
$html .= "</html>";
return $html;
}
2020-04-03 15:56:04 +02:00
}