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