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
36 lines
908 B
<?php namespace Wpstudio\AssetsManifest\Classes;
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class ManifestReader implements Arrayable
|
|
{
|
|
private Collection $manifest;
|
|
|
|
/**
|
|
* @param string $manifestPath
|
|
* @throws AssetsManifestException
|
|
*/
|
|
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);
|
|
}
|
|
|
|
$this->manifest = collect(json_decode(file_get_contents($manifestPath), true));
|
|
}
|
|
|
|
public function get(string $assetName)
|
|
{
|
|
return $this->manifest->offsetGet($assetName);
|
|
}
|
|
|
|
public function toArray()
|
|
{
|
|
return $this->manifest;
|
|
}
|
|
}
|