web-base/Core/Elements/Script.class.php

45 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2020-02-09 23:02:19 +01:00
<?php
2022-11-18 18:06:46 +01:00
namespace Core\Elements;
2020-02-09 23:02:19 +01:00
2020-04-04 01:15:59 +02:00
class Script extends StaticView {
2020-02-09 23:02:19 +01:00
const MIME_TEXT_JAVASCRIPT = "text/javascript";
2020-04-04 01:15:59 +02:00
const CORE = "/js/script.js";
const JQUERY = "/js/jquery.min.js";
const INSTALL = "/js/install.js";
2020-04-03 22:10:21 +02:00
const BOOTSTRAP = "/js/bootstrap.bundle.min.js";
2020-07-01 22:13:50 +02:00
const ACCOUNT = "/js/account.js";
2021-11-11 14:25:26 +01:00
const FONTAWESOME = "/js/fontawesome-all.min.js";
2020-02-09 23:02:19 +01:00
2020-04-03 15:56:04 +02:00
private string $type;
private string $content;
2020-04-03 17:39:58 +02:00
private string $src;
2021-12-08 16:53:43 +01:00
private ?string $nonce;
2020-02-09 23:02:19 +01:00
function __construct($type, $src, $content = "") {
2020-04-03 17:39:58 +02:00
$this->src = $src;
2020-02-09 23:02:19 +01:00
$this->type = $type;
$this->content = $content;
2021-12-08 16:53:43 +01:00
$this->nonce = null;
2020-02-09 23:02:19 +01:00
}
2021-04-02 22:47:11 +02:00
function getCode(): string {
2021-12-08 16:53:43 +01:00
$attributes = ["type" => $this->type];
if (!empty($this->src)) {
$attributes["src"] = $this->src;
}
if (!empty($this->nonce)) {
$attributes["nonce"] = $this->nonce;
}
// TODO: do we need to escape the content here?
return html_tag("script", $attributes, $this->content, false);
2021-12-08 16:53:43 +01:00
}
public function setNonce(string $nonce) {
$this->nonce = $nonce;
2020-02-09 23:02:19 +01:00
}
2020-04-03 15:56:04 +02:00
}