assets class
This commit is contained in:
parent
32d1e93e73
commit
64dad0aaf9
66
kernel/Assets.php
Normal file
66
kernel/Assets.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace kernel;
|
||||
|
||||
class Assets
|
||||
{
|
||||
protected array $jsHeader = [];
|
||||
protected array $jsBody = [];
|
||||
|
||||
protected array $css = [];
|
||||
|
||||
protected string $resourceURI = "/resource";
|
||||
|
||||
public function __construct(string $resourceURI)
|
||||
{
|
||||
$this->setResourceURI($resourceURI);
|
||||
$this->createCSS();
|
||||
$this->createJS();
|
||||
}
|
||||
|
||||
protected function createCSS(){}
|
||||
protected function createJS(){}
|
||||
|
||||
public function setResourceURI(string $resourceURI): void
|
||||
{
|
||||
$this->resourceURI = $resourceURI;
|
||||
}
|
||||
|
||||
public function registerJS(string $slug, string $resource, bool $body = true, bool $addResourceURI = true): void
|
||||
{
|
||||
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
|
||||
if ($body) {
|
||||
$this->jsBody[$slug] = $resource;
|
||||
} else {
|
||||
$this->jsHeader[$slug] = $resource;
|
||||
}
|
||||
}
|
||||
|
||||
public function registerCSS(string $slug, string $resource, bool $addResourceURI = true): void
|
||||
{
|
||||
$resource = $addResourceURI ? $this->resourceURI . $resource : $resource;
|
||||
$this->css[$slug] = $resource;
|
||||
}
|
||||
|
||||
public function getJSAsStr(bool $body = true): void
|
||||
{
|
||||
if ($body) {
|
||||
foreach ($this->jsBody as $key => $item){
|
||||
echo "<script src='$item'></script>";
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($this->jsHeader as $key => $item){
|
||||
echo "<script src='$item'></script>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getCSSAsSTR(): void
|
||||
{
|
||||
foreach ($this->css as $key => $item){
|
||||
echo "<link rel='stylesheet' href='$item'>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
25
kernel/admin_themes/default/DefaultAdminThemeAssets.php
Normal file
25
kernel/admin_themes/default/DefaultAdminThemeAssets.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\admin_themes\default;
|
||||
|
||||
use kernel\Assets;
|
||||
|
||||
class DefaultAdminThemeAssets extends Assets
|
||||
{
|
||||
|
||||
protected function createJS(): void
|
||||
{
|
||||
$this->registerJS(slug: "jquery", resource: "/js/jquery.min.js");
|
||||
$this->registerJS(slug: "popper", resource: "/js/popper.js");
|
||||
$this->registerJS(slug: "bootstrap", resource: "/js/bootstrap.min.js");
|
||||
$this->registerJS(slug: "main", resource: "/js/main.js");
|
||||
}
|
||||
|
||||
protected function createCSS()
|
||||
{
|
||||
$this->registerCSS(slug: "font-awesome", resource: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css", addResourceURI: false);
|
||||
$this->registerCSS(slug: "bootstrap", resource: "/css/bootstrap.min.css");
|
||||
$this->registerCSS(slug: "style", resource: "/css/style.css");
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
* @var \kernel\CgView $view
|
||||
*/
|
||||
\Josantonius\Session\Facades\Session::start();
|
||||
$assets = new \kernel\admin_themes\default\DefaultAdminThemeAssets($resources)
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
@ -17,9 +18,8 @@
|
||||
|
||||
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?= $resources ?>/css/style.css">
|
||||
<?php $assets->getCSSAsSTR(); ?>
|
||||
<?php $assets->getJSAsStr(body: false); ?>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -92,9 +92,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="<?= $resources ?>/js/jquery.min.js"></script>
|
||||
<script src="<?= $resources ?>/js/popper.js"></script>
|
||||
<script src="<?= $resources ?>/js/bootstrap.min.js"></script>
|
||||
<script src="<?= $resources ?>/js/main.js"></script>
|
||||
<?php $assets->getJSAsStr(); ?>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user