2021-09-13 17:15:33 +03:00
|
|
|
<?php namespace Wpstudio\AssetsManifest\Classes;
|
|
|
|
|
2022-03-19 19:01:54 +03:00
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
class ManifestReader implements Arrayable
|
2021-09-13 17:15:33 +03:00
|
|
|
{
|
2022-03-19 19:01:54 +03:00
|
|
|
private Collection $manifest;
|
2021-09-13 17:15:33 +03:00
|
|
|
|
2022-01-09 19:09:18 +03:00
|
|
|
/**
|
|
|
|
* @param string $manifestPath
|
|
|
|
* @throws AssetsManifestException
|
|
|
|
*/
|
2021-09-13 17:15:33 +03:00
|
|
|
public function __construct(string $manifestPath)
|
|
|
|
{
|
2022-01-09 19:09:18 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-01-09 19:09:18 +03:00
|
|
|
public function get(string $assetName)
|
2021-09-13 17:15:33 +03:00
|
|
|
{
|
2022-03-19 19:01:54 +03:00
|
|
|
return $this->manifest->offsetGet($assetName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toArray()
|
|
|
|
{
|
|
|
|
return $this->manifest;
|
2021-09-13 17:15:33 +03:00
|
|
|
}
|
|
|
|
}
|