diff options
Diffstat (limited to 'src/Assets.php')
-rw-r--r-- | src/Assets.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Assets.php b/src/Assets.php index 981ac76..962041f 100644 --- a/src/Assets.php +++ b/src/Assets.php @@ -12,6 +12,7 @@ class Assets private array $files = []; private array $queuedHeadFiles = []; private array $queuedFooterFiles = []; + private array $queuedFileHashs = []; public function addManifest( string $name, @@ -81,10 +82,28 @@ class Assets } } + private function pushFile(File $file, bool $footer): void + { + $hash = $file->hash(); + + if ($this->queuedFileHashes[$hash] ?? false) { + throw new Exception("File {$file} is already queued"); + } + else { + $this->queuedFileHashes[$hash] = true; + $queue = $footer ? 'queuedFooterFiles' : 'queuedHeadFiles'; + $this->{$queue}[] = $file; + } + } + public function queueFile(string $file, string $fileClass, bool $footer): void { $file = new FileString($file); $manifest = $this->getFileManifest($file); + $url = $manifest->getUrl($file->fileUri) ?? $file->fileUri; + + $file = new $fileClass($url); + $this->pushFile($file, $footer); } public function queueScript(string $file, bool $footer = true): void |