Files
assetsmanifest-plugin/classes/ManifestReader.php

37 lines
908 B
PHP
Raw Normal View History

2021-09-13 17:15:33 +03:00
<?php namespace Wpstudio\AssetsManifest\Classes;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Collection;
class ManifestReader implements Arrayable
2021-09-13 17:15:33 +03:00
{
private Collection $manifest;
2021-09-13 17:15:33 +03:00
/**
* @param string $manifestPath
* @throws AssetsManifestException
*/
2021-09-13 17:15:33 +03:00
public function __construct(string $manifestPath)
{
if (!file_exists($manifestPath)) {
throw new AssetsManifestException('Not found: ' . $manifestPath);
}
if (!is_readable($manifestPath)) {
throw new AssetsManifestException('Not readable: ' . $manifestPath);
}
2022-07-17 14:34:49 +03:00
$this->manifest = collect(json_decode(file_get_contents($manifestPath), true));
2021-09-13 17:15:33 +03:00
}
public function get(string $assetName)
2021-09-13 17:15:33 +03:00
{
return $this->manifest->offsetGet($assetName);
}
public function toArray()
{
return $this->manifest;
2021-09-13 17:15:33 +03:00
}
}