start
This commit is contained in:
44
src/App/Assets.php
Normal file
44
src/App/Assets.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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; }
|
||||
}
|
||||
Reference in New Issue
Block a user