45 lines
1.2 KiB
PHP
Executable File
45 lines
1.2 KiB
PHP
Executable File
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App;
|
|
|
|
final class Assets
|
|
{
|
|
private array $styles = [];
|
|
private array $scriptsHeader = [];
|
|
private array $scriptsFooter = [];
|
|
|
|
public function __construct(private Config $config) {}
|
|
|
|
public function addStyle(string $href, string $priority = 'normal', ?string $version = null): void
|
|
{
|
|
$version ??= $this->config->assetVersion;
|
|
$this->styles[] = [
|
|
'href' => $href,
|
|
'priority' => $priority,
|
|
'version' => $version,
|
|
];
|
|
}
|
|
|
|
public function addScript(string $src, string $pos = 'footer', bool $defer = true, bool $async = false, ?string $version = null): void
|
|
{
|
|
$version ??= $this->config->assetVersion;
|
|
$row = [
|
|
'src' => $src,
|
|
'defer' => $defer,
|
|
'async' => $async,
|
|
'version' => $version,
|
|
];
|
|
|
|
if ($pos === 'header') {
|
|
$this->scriptsHeader[] = $row;
|
|
} else {
|
|
$this->scriptsFooter[] = $row;
|
|
}
|
|
}
|
|
|
|
public function styles(): array { return $this->styles; }
|
|
public function headerScripts(): array { return $this->scriptsHeader; }
|
|
public function footerScripts(): array { return $this->scriptsFooter; }
|
|
}
|