| 1 |
<?php |
| 2 |
|
| 3 |
namespace AATXT\App\Utilities; |
| 4 |
|
| 5 |
final class AssetsManager |
| 6 |
{ |
| 7 |
public function __construct() |
| 8 |
{ |
| 9 |
} |
| 10 |
|
| 11 |
public static function make(): AssetsManager |
| 12 |
{ |
| 13 |
return new self(); |
| 14 |
} |
| 15 |
|
| 16 |
public function getAssetUrl(string $filename, bool $isStyle = false): string |
| 17 |
{ |
| 18 |
$manifestPath = AATXT_ABSPATH . '/dist/.vite/manifest.json'; |
| 19 |
|
| 20 |
if (!file_exists($manifestPath)) { |
| 21 |
return ''; |
| 22 |
} |
| 23 |
|
| 24 |
$manifest = json_decode(file_get_contents($manifestPath), true); |
| 25 |
|
| 26 |
$entry = $manifest[$filename] ?? null; |
| 27 |
|
| 28 |
if (!$entry) { |
| 29 |
return ''; |
| 30 |
} |
| 31 |
$file = $isStyle && isset($entry['css']) ? $entry['css'][0] : $entry['file']; |
| 32 |
|
| 33 |
return AATXT_URL . 'dist/' . $file; |
| 34 |
} |
| 35 |
|
| 36 |
} |
| 37 |
|