diff options
| author | Sam Light <sam@lightscale.co.uk> | 2025-03-31 22:08:20 +0100 | 
|---|---|---|
| committer | Sam Light <samlight1994@gmail.com> | 2025-03-31 22:08:20 +0100 | 
| commit | d700b3b5772022902948430d076fc3c0a00f20ef (patch) | |
| tree | 781311f48a250474fb8f5a5034370678245bd3cd /src | |
| parent | 41605e2ab4b8de04cd1c05a4cfe95b822ba46ae1 (diff) | |
Changes to Assets class manifest function
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);      }  } | 
