1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (!function_exists('route_alias')) { |
4
|
|
|
/** |
5
|
|
|
* Get URL-path (alias/system path) for entity. |
6
|
|
|
* |
7
|
|
|
* @param string $systemName |
8
|
|
|
* @param array $parameters |
9
|
|
|
* @param bool $absolute |
10
|
|
|
* @param bool $forceWithLocalePreffix |
11
|
|
|
* @return string |
12
|
|
|
*/ |
13
|
|
|
function route_alias(string $systemName, $parameters = [], $absolute = true, $forceWithLocalePreffix = false): string |
14
|
|
|
{ |
15
|
|
|
return app()->make(\Fomvasss\UrlAliases\UrlAlias::class)->route($systemName, $parameters, $absolute, $forceWithLocalePreffix); |
|
|
|
|
16
|
|
|
} |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
if (!function_exists('url_alias_current')) { |
21
|
|
|
/** |
22
|
|
|
* Get current url alias path or system path. |
23
|
|
|
* |
24
|
|
|
* @param string $str |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
function url_alias_current($absolute = true): string |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
return app()->make(\Fomvasss\UrlAliases\UrlAlias::class)->current($absolute); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (!function_exists('array_wrap')) { |
34
|
|
|
/** |
35
|
|
|
* @param $value |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
function array_wrap($value) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
if (is_null($value)) { |
41
|
|
|
return []; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return ! is_array($value) ? [$value] : $value; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!function_exists('is_url')) { |
49
|
|
|
/** |
50
|
|
|
* Check the string is url. |
51
|
|
|
* |
52
|
|
|
* @param string $str |
53
|
|
|
* @return mixed |
54
|
|
|
*/ |
55
|
|
|
function is_url(string $str) |
56
|
|
|
{ |
57
|
|
|
return filter_var($str, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!function_exists('prepare_url_path')) { |
62
|
|
|
/** |
63
|
|
|
* Remove sheme & current domain from url. |
64
|
|
|
* |
65
|
|
|
* @param string $str |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
function prepare_url_path(string $url = null) |
69
|
|
|
{ |
70
|
|
|
$path = parse_url($url)['path'] ?? '/'; |
71
|
|
|
|
72
|
|
|
// TODO: to replace request()->root() |
73
|
|
|
if ($path === '/' || $url === '/' || $url === request()->root()) { |
|
|
|
|
74
|
|
|
return '/'; |
75
|
|
|
} elseif ($path) { |
76
|
|
|
return trim($path, '/'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return null; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (!function_exists('url_path_segments')) { |
84
|
|
|
/** |
85
|
|
|
* @param string $path |
86
|
|
|
* @param null $index |
|
|
|
|
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
function url_path_segments(string $path, int $index = null) |
90
|
|
|
{ |
91
|
|
|
$segments = explode('/', $path); |
92
|
|
|
|
93
|
|
|
$array = array_values(array_filter($segments, function ($value) { |
94
|
|
|
return $value !== ''; |
95
|
|
|
})); |
96
|
|
|
|
97
|
|
|
if ($index) { |
|
|
|
|
98
|
|
|
return $array[$index - 1] ?? ''; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $array; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|