62 lines
2.4 KiB
PHP
62 lines
2.4 KiB
PHP
<?php
|
|
namespace YTKNS;
|
|
|
|
final class PageBuilder {
|
|
private $tagHtml;
|
|
private $tagHead;
|
|
private $tagBody;
|
|
private $tagTitle;
|
|
private $tagContainer;
|
|
|
|
public function __construct(string $pageTitle) {
|
|
$sharedCss = '//' . Config::get('domain.main') . '/assets/shared.css?v=' . hash_file('md5', YTKNS_PUB . '/assets/shared.css');
|
|
$sharedJs = '//' . Config::get('domain.main') . '/assets/shared.js?v=' . hash_file('md5', YTKNS_PUB . '/assets/shared.js');
|
|
|
|
$this->tagHtml = new HtmlTag('html');
|
|
$this->tagHtml->appendChild($this->tagHead = new HtmlTag('head'));
|
|
$this->tagHtml->appendChild($this->tagBody = new HtmlTag('body'));
|
|
$this->tagHead->appendChild(new HtmlTag('meta', ['charset' => 'utf-8'], true));
|
|
$this->tagHead->appendChild(new HtmlTag('meta', ['name' => 'viewport', 'content' => 'width=device-width, initial-scale=1'], true));
|
|
$this->tagHead->appendChild($this->tagTitle = new HtmlTag('title'));
|
|
$this->tagHead->appendChild(new HtmlTag('link', ['href' => $sharedCss, 'type' => 'text/css', 'rel' => 'stylesheet'], true));
|
|
$this->tagHead->appendChild(new HtmlTag('script', ['charset' => 'utf-8', 'src' => $sharedJs]));
|
|
$this->tagBody->appendChild($this->tagContainer = new HtmlTag('div', ['id' => 'container']));
|
|
$this->setTitle($pageTitle);
|
|
}
|
|
|
|
public function getHtml(): HtmlTag {
|
|
return $this->tagHtml;
|
|
}
|
|
public function getHead(): HtmlTag {
|
|
return $this->tagHead;
|
|
}
|
|
public function getBody(): HtmlTag {
|
|
return $this->tagBody;
|
|
}
|
|
public function getContainer(): HtmlTag {
|
|
return $this->tagContainer;
|
|
}
|
|
|
|
public function setTitle(string $title): void {
|
|
$this->tagTitle->setTextContent($title);
|
|
}
|
|
|
|
public function getElementsByTagName(string $tagName): array {
|
|
return $this->tagHtml->getElementsByTagName($tagName);
|
|
}
|
|
public function getElementsByClassName(string $className): array {
|
|
return $this->tagHtml->getElementsByClassName($className);
|
|
}
|
|
public function getElementById(string $idString): ?HtmlTag {
|
|
return $this->tagHtml->getElementById($idString);
|
|
}
|
|
|
|
public function serialise(): string {
|
|
return '<!doctype html>' . $this->tagHtml->asHTML();
|
|
}
|
|
|
|
public function __toString(): string {
|
|
return $this->serialise();
|
|
}
|
|
}
|