1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
if (! function_exists('revision')) { |
5
|
|
|
/** |
6
|
|
|
* Get the revisioned asset path. |
7
|
|
|
* |
8
|
|
|
* @param string $path |
9
|
|
|
* @return string |
10
|
|
|
*/ |
11
|
|
|
function revision($path) |
12
|
|
|
{ |
13
|
|
|
if ($rev = array_get(config('assets-version'), trim($path, '/'))) { |
14
|
|
|
return $path.'?'.$rev; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
return $path; |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if (! function_exists('is_app')) { |
22
|
|
|
/** |
23
|
|
|
* Determine the current sub application. |
24
|
|
|
* |
25
|
|
|
* @param string $identifier |
26
|
|
|
* @return bool |
27
|
|
|
*/ |
28
|
|
|
function is_app($identifier) |
29
|
|
|
{ |
30
|
|
|
return ($appUrl = config('support.url.'.$identifier)) && |
31
|
|
|
starts_with( |
32
|
|
|
preg_replace('#^https?://#', '', app('request')->url()), |
33
|
|
|
preg_replace('#^https?://#', '', $appUrl) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if (! function_exists('app_url')) { |
39
|
|
|
/** |
40
|
|
|
* Generate an absolute URL to the given path. |
41
|
|
|
* |
42
|
|
|
* @param string $path |
43
|
|
|
* @param mixed $query |
44
|
|
|
* @param string $identifier |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
function app_url($path = '', $query = [], $identifier = '') |
48
|
|
|
{ |
49
|
|
|
$path = trim($path, '/'); |
50
|
|
|
if (! empty($path)) { |
51
|
|
|
$path = '/'.$path; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($query) { |
55
|
|
|
$query = http_build_query($query); |
56
|
|
|
if (! empty($query)) { |
57
|
|
|
$path .= (str_contains($path, ['?', '&', '#']) ? '&' : '?').$query; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$root = $identifier ? config('support.url.'.$identifier) : config('app.url'); |
62
|
|
|
|
63
|
|
|
return $root.$path; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (! function_exists('asset_url')) { |
68
|
|
|
/** |
69
|
|
|
* Generate an asset URL to the given path. |
70
|
|
|
* |
71
|
|
|
* @param string $path |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
function asset_url($path, $identifier = 'asset') |
75
|
|
|
{ |
76
|
|
|
return app('url')->assetFrom( |
77
|
|
|
config('support.url.'.$identifier), |
78
|
|
|
revision($path) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (! function_exists('cdn_url')) { |
84
|
|
|
/** |
85
|
|
|
* Generate an asset CDN URL to the given path. |
86
|
|
|
* |
87
|
|
|
* @param string $path |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
function cdn_url($path) |
91
|
|
|
{ |
92
|
|
|
return asset_url($path, 'cdn'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|