You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
908 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php namespace Wpstudio\AssetsManifest\Classes;
  2. use Illuminate\Contracts\Support\Arrayable;
  3. use Illuminate\Support\Collection;
  4. class ManifestReader implements Arrayable
  5. {
  6. private Collection $manifest;
  7. /**
  8. * @param string $manifestPath
  9. * @throws AssetsManifestException
  10. */
  11. public function __construct(string $manifestPath)
  12. {
  13. if (!file_exists($manifestPath)) {
  14. throw new AssetsManifestException('Not found: ' . $manifestPath);
  15. }
  16. if (!is_readable($manifestPath)) {
  17. throw new AssetsManifestException('Not readable: ' . $manifestPath);
  18. }
  19. $this->manifest = collect(json_decode(file_get_contents($manifestPath), true));
  20. }
  21. public function get(string $assetName)
  22. {
  23. return $this->manifest->offsetGet($assetName);
  24. }
  25. public function toArray()
  26. {
  27. return $this->manifest;
  28. }
  29. }