diff options
Diffstat (limited to 'src/Manifest.php')
| -rw-r--r-- | src/Manifest.php | 21 | 
1 files changed, 17 insertions, 4 deletions
| diff --git a/src/Manifest.php b/src/Manifest.php index b7c5e96..655945b 100644 --- a/src/Manifest.php +++ b/src/Manifest.php @@ -2,19 +2,26 @@  namespace Lightscale\LaralightAssets; +use Illuminate\Support\Str; +  class Manifest  { -    private ?array $data; +    private ?array $data = null; +    private string $basePath;      public function __construct(          private string $path,          private string $baseUrl, +        ?string $basePath = null,          private string $parserClass = JsonManifestParser::class, -    ) {} +    ) { +        $fileName = Str::afterLast($path, '/'); +        $this->basePath = Str::replaceLast("/{$fileName}", '', $path); +    }      private function readFile(): string      { -        return filegetcontents($this->path); +        return file_get_contents($this->path);      }      private function loadData(): void @@ -30,6 +37,12 @@ class Manifest          return $this->data;      } + +    public function getDir(): string +    { +        return $this->basePath; +    } +      public function getFile(string $file): ?string      {          return $this->getData()[$file] ?? null; @@ -38,7 +51,7 @@ class Manifest      public function getUrl(string $file): ?string      {          $file = $this->getFile($file); -        return $file === null ? null : "{$this->baseUrl}/{$file}"; +        return $file === null ? null : asset("{$this->baseUrl}/{$file}");      }      public function getPath(string $file): ?string | 
