diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Assets.php | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/Assets.php b/src/Assets.php index a431ffb..352bb2b 100644 --- a/src/Assets.php +++ b/src/Assets.php @@ -2,9 +2,11 @@ namespace Lightscale\LaralightAssets; +use InvalidArgumentException; + class Assets { - private string $defaultManifest; + private ?string $defaultManifest = null; private array $manifests = []; private array $manifestsParsers = []; private array $files = []; @@ -49,9 +51,50 @@ class Assets return $this->getManifests()[$name]; } - public function getDefaultManifest(): Manifest + public function setDefaultManifest(?string $name): void + { + if ($name !== null && ($this->manifests[$name] ?? false) === false) { + throw new InvalidArgumentException( + "No manifest with name {$name} exists" + ); + } + + $this->defaultManifest = $name; + } + + public function getDefaultManifest(): ?Manifest + { + return ( + $this->defaultManifest === null ? + null : + $this->getManifest($this->defaultManifest) + ); + } + + public function getFileManifest(FileString $file): ?Manifest + { + if ($file->manifestName !== null) { + return $this->getManifest($file->manifestName); + } + else { + return $this->getDefaultManifest(); + } + } + + public function queueFile(string $file, string $fileClass, bool $footer): void + { + $file = new FileString($file); + $manifest = $this->getFileManifest($file); + } + + public function queueScript(string $file, bool $footer = true): void + { + $this->queueFile($file, ScriptFile::class, $footer); + } + + public function queueStyle(string $file): void { - return $this->getManifest($this->defaultManifest); + $this->queueFile($file, StyleFile::class, false); } } |