-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.php
41 lines (36 loc) · 1.26 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use Illuminate\Support\Str;
use Illuminate\Support\HtmlString;
if (! function_exists('mix')) {
/**
* Get the path to a versioned Mix file.
*
* @param string $path
* @param string $manifestDirectory
* @return \Illuminate\Support\HtmlString
*
* @throws \Exception
*/
function mix($path, $manifestDirectory = '') {
static $manifests = [];
if (! Str::startsWith($path, '/')) {
$path = "/{$path}";
}
if ($manifestDirectory && ! Str::startsWith($manifestDirectory, '/')) {
$manifestDirectory = "/{$manifestDirectory}";
}
$manifestPath = $_SERVER['DOCUMENT_ROOT'] . $manifestDirectory.'/mix-manifest.json';
if (! isset($manifests[$manifestPath])) {
if (! file_exists($manifestPath)) {
throw new Exception('The Mix manifest does not exist.');
}
$manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
}
$manifest = $manifests[$manifestPath];
if (! isset($manifest[$path])) {
new Exception("Unable to locate Mix file: {$path}.");
return $path;
}
return new HtmlString($manifestDirectory.$manifest[$path]);
}
}