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