Application::staticUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace App;
4
5
use Illuminate\Foundation\Application as IlluminateApplication;
6
use InvalidArgumentException;
7
8
/**
9
 * Extends \Illuminate\Foundation\Application to override some defaults.
10
 */
11
class Application extends IlluminateApplication
12
{
13
    /**
14
     * Current Koel version. Must start with a v, and is synced with git tags/releases.
15
     *
16
     * @link https://github.com/phanan/koel/releases
17
     */
18
    public const KOEL_VERSION = 'v4.2.2';
19
20
    /**
21
     * We have merged public path and base path.
22
     *
23
     * @return string
24
     */
25 132
    public function publicPath()
26
    {
27 132
        return $this->basePath;
28
    }
29
30
    /**
31
     * Loads a revision'ed asset file, making use of gulp-rev
32
     * This is a copycat of L5's Elixir, but catered to our directory structure.
33
     *
34
     * @throws InvalidArgumentException
35
     */
36 2
    public function rev(string $file, string $manifestFile = null): string
37
    {
38 2
        static $manifest = null;
39
40 2
        $manifestFile = $manifestFile ?: public_path('public/mix-manifest.json');
41
42 2
        if ($manifest === null) {
43 1
            $manifest = json_decode(file_get_contents($manifestFile), true);
44
        }
45
46 2
        if (isset($manifest[$file])) {
47 2
            return file_exists(public_path('public/hot'))
48
                    ? "http://localhost:8080{$manifest[$file]}"
49 2
                    : $this->staticUrl("public{$manifest[$file]}");
50
        }
51
52
        throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
53
    }
54
55
    /**
56
     * Get a URL for static file requests.
57
     * If this installation of Koel has a CDN_URL configured, use it as the base.
58
     * Otherwise, just use a full URL to the asset.
59
     *
60
     * @param string $name The additional resource name/path.
61
     */
62 15
    public function staticUrl(?string $name = null): string
63
    {
64 15
        $cdnUrl = trim(config('koel.cdn.url'), '/ ');
65
66 15
        return $cdnUrl ? $cdnUrl.'/'.trim(ltrim($name, '/')) : trim(asset($name));
67
    }
68
}
69