Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Foundation;
4
 
5
use Exception;
6
use Illuminate\Support\HtmlString;
7
use Illuminate\Support\Str;
8
 
9
class Mix
10
{
11
    /**
12
     * Get the path to a versioned Mix file.
13
     *
14
     * @param  string  $path
15
     * @param  string  $manifestDirectory
16
     * @return \Illuminate\Support\HtmlString|string
17
     *
18
     * @throws \Exception
19
     */
20
    public function __invoke($path, $manifestDirectory = '')
21
    {
22
        static $manifests = [];
23
 
24
        if (! str_starts_with($path, '/')) {
25
            $path = "/{$path}";
26
        }
27
 
28
        if ($manifestDirectory && ! str_starts_with($manifestDirectory, '/')) {
29
            $manifestDirectory = "/{$manifestDirectory}";
30
        }
31
 
32
        if (is_file(public_path($manifestDirectory.'/hot'))) {
33
            $url = rtrim(file_get_contents(public_path($manifestDirectory.'/hot')));
34
 
35
            $customUrl = app('config')->get('app.mix_hot_proxy_url');
36
 
37
            if (! empty($customUrl)) {
38
                return new HtmlString("{$customUrl}{$path}");
39
            }
40
 
41
            if (Str::startsWith($url, ['http://', 'https://'])) {
42
                return new HtmlString(Str::after($url, ':').$path);
43
            }
44
 
45
            return new HtmlString("//localhost:8080{$path}");
46
        }
47
 
48
        $manifestPath = public_path($manifestDirectory.'/mix-manifest.json');
49
 
50
        if (! isset($manifests[$manifestPath])) {
51
            if (! is_file($manifestPath)) {
52
                throw new Exception("Mix manifest not found at: {$manifestPath}");
53
            }
54
 
55
            $manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
56
        }
57
 
58
        $manifest = $manifests[$manifestPath];
59
 
60
        if (! isset($manifest[$path])) {
61
            $exception = new Exception("Unable to locate Mix file: {$path}.");
62
 
63
            if (! app('config')->get('app.debug')) {
64
                report($exception);
65
 
66
                return $path;
67
            } else {
68
                throw $exception;
69
            }
70
        }
71
 
72
        return new HtmlString(app('config')->get('app.mix_url').$manifestDirectory.$manifest[$path]);
73
    }
74
}