fomvasss /
laravel-url-aliases
| 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); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 16 | } |
||||
| 17 | } |
||||
| 18 | |||||
| 19 | if (!function_exists('url_alias_current')) { |
||||
| 20 | /** |
||||
| 21 | * Get current url alias path or system path. |
||||
| 22 | * |
||||
| 23 | * @param string $str |
||||
| 24 | * @return array |
||||
| 25 | */ |
||||
| 26 | function url_alias_current($absolute = true): string |
||||
| 27 | { |
||||
| 28 | return app()->make(\Fomvasss\UrlAliases\UrlAlias::class)->current($absolute); |
||||
|
0 ignored issues
–
show
The function
app was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 29 | } |
||||
| 30 | } |
||||
| 31 | |||||
| 32 | if (!function_exists('array_wrap')) { |
||||
| 33 | /** |
||||
| 34 | * @param $value |
||||
| 35 | * @return array |
||||
| 36 | */ |
||||
| 37 | function array_wrap($value) |
||||
| 38 | { |
||||
| 39 | if (is_null($value)) { |
||||
| 40 | return []; |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | return ! is_array($value) ? [$value] : $value; |
||||
| 44 | } |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | if (!function_exists('is_url')) { |
||||
| 48 | /** |
||||
| 49 | * Check the string is url. |
||||
| 50 | * |
||||
| 51 | * @param string $str |
||||
| 52 | * @return mixed |
||||
| 53 | */ |
||||
| 54 | function is_url(string $str) |
||||
| 55 | { |
||||
| 56 | return filter_var($str, FILTER_VALIDATE_URL); |
||||
| 57 | } |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | if (!function_exists('prepare_url_path')) { |
||||
| 61 | /** |
||||
| 62 | * Remove sheme & current domain from url. |
||||
| 63 | * |
||||
| 64 | * @param string $str |
||||
| 65 | * @return mixed |
||||
| 66 | */ |
||||
| 67 | function prepare_url_path(string $url = null) |
||||
| 68 | { |
||||
| 69 | $path = parse_url($url)['path'] ?? '/'; |
||||
| 70 | |||||
| 71 | // TODO: to replace request()->root() |
||||
| 72 | if ($path === '/' || $url === '/' || $url === request()->root()) { |
||||
|
0 ignored issues
–
show
The function
request was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 73 | return '/'; |
||||
| 74 | } elseif ($path) { |
||||
| 75 | return trim($path, '/'); |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | return null; |
||||
| 79 | } |
||||
| 80 | } |
||||
| 81 | |||||
| 82 | if (!function_exists('url_path_segments')) { |
||||
| 83 | /** |
||||
| 84 | * @param string $path |
||||
| 85 | * @param null $index |
||||
| 86 | * @return mixed |
||||
| 87 | */ |
||||
| 88 | function url_path_segments(string $path, int $index = null) |
||||
| 89 | { |
||||
| 90 | $segments = explode('/', $path); |
||||
| 91 | |||||
| 92 | $array = array_values(array_filter($segments, function ($value) { |
||||
| 93 | return $value !== ''; |
||||
| 94 | })); |
||||
| 95 | |||||
| 96 | if ($index) { |
||||
|
0 ignored issues
–
show
The expression
$index of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
Loading history...
|
|||||
| 97 | return $array[$index - 1] ?? ''; |
||||
| 98 | } |
||||
| 99 | |||||
| 100 | return $array; |
||||
| 101 | } |
||||
| 102 | } |
||||
| 103 | |||||
| 104 |