replaced confusing loadView behaviour
This commit is contained in:
@@ -17,7 +17,7 @@ class Link extends StaticView {
|
||||
private string $href;
|
||||
private ?string $nonce;
|
||||
|
||||
function __construct($rel, $href, $type = "") {
|
||||
function __construct(string $rel, string $href, string $type = "") {
|
||||
$this->href = $href;
|
||||
$this->type = $type;
|
||||
$this->rel = $rel;
|
||||
|
||||
@@ -18,7 +18,7 @@ class Script extends StaticView {
|
||||
private string $src;
|
||||
private ?string $nonce;
|
||||
|
||||
function __construct($type, $src, $content = "") {
|
||||
function __construct(string $type, string $src, string $content = "") {
|
||||
$this->src = $src;
|
||||
$this->type = $type;
|
||||
$this->content = $content;
|
||||
@@ -35,8 +35,8 @@ class Script extends StaticView {
|
||||
$attributes["nonce"] = $this->nonce;
|
||||
}
|
||||
|
||||
// TODO: do we need to escape the content here?
|
||||
return html_tag("script", $attributes, $this->content, false);
|
||||
$escapedContent = str_replace("</script>", "<\\/script>", $this->content);
|
||||
return html_tag("script", $attributes, $escapedContent, false);
|
||||
}
|
||||
|
||||
public function setNonce(string $nonce) {
|
||||
|
||||
@@ -8,6 +8,7 @@ use Core\Objects\Router\Router;
|
||||
use Core\Objects\Search\Searchable;
|
||||
use Core\Objects\Search\SearchQuery;
|
||||
use Core\Objects\Search\SearchResult;
|
||||
use Core\Elements\View;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
@@ -126,13 +127,13 @@ class TemplateDocument extends Document {
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadView(string $class): array {
|
||||
protected function loadView(string $class): View {
|
||||
$view = new $class($this);
|
||||
$view->loadParameters($this->parameters);
|
||||
if ($view->getTitle()) {
|
||||
$this->title = $view->getTitle();
|
||||
}
|
||||
return $this->parameters;
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function doSearch(SearchQuery $query, DocumentRoute $route): array {
|
||||
|
||||
@@ -7,15 +7,15 @@ use Core\Objects\Context;
|
||||
abstract class View extends StaticView {
|
||||
|
||||
private Document $document;
|
||||
private bool $loadView;
|
||||
private bool $autoload;
|
||||
protected string $title;
|
||||
protected array $langModules;
|
||||
|
||||
public function __construct(Document $document, bool $loadView = true) {
|
||||
public function __construct(Document $document, bool $autoload = true) {
|
||||
$this->document = $document;
|
||||
$this->title = "Untitled View";
|
||||
$this->langModules = [];
|
||||
$this->loadView = $loadView;
|
||||
$this->autoload = $autoload;
|
||||
}
|
||||
|
||||
public function getTitle(): string { return $this->title; }
|
||||
@@ -52,7 +52,7 @@ abstract class View extends StaticView {
|
||||
public function getCode(): string {
|
||||
|
||||
// Load metadata + head (title, scripts, includes, ...)
|
||||
if ($this->loadView) {
|
||||
if ($this->autoload) {
|
||||
$this->loadView();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user