Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Assets | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAssetPath | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Helpers; |
6 | |
7 | class Assets |
8 | { |
9 | protected string $manifestFile = 'manifest.json'; |
10 | |
11 | /** |
12 | * @param string $assetsPath Directory containing assets |
13 | */ |
14 | public function __construct(protected string $assetsPath) |
15 | { |
16 | } |
17 | |
18 | public function getAssetPath(string $asset): string |
19 | { |
20 | $manifest = $this->assetsPath . DIRECTORY_SEPARATOR . $this->manifestFile; |
21 | if (is_readable($manifest)) { |
22 | $manifest = json_decode(file_get_contents($manifest), true); |
23 | |
24 | if (isset($manifest[$asset])) { |
25 | $asset = $manifest[$asset]; |
26 | } |
27 | } |
28 | |
29 | return $asset; |
30 | } |
31 | } |