From 342f14b6c5345554d9c3ad1a1f6b7c4aa20c8cef Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 8 Jul 2022 15:07:00 +0300 Subject: [PATCH] feat(helpers): add `url` function --- src/flextype/helpers/url.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/flextype/helpers/url.php b/src/flextype/helpers/url.php index a9451839..8ef19ee7 100644 --- a/src/flextype/helpers/url.php +++ b/src/flextype/helpers/url.php @@ -182,7 +182,7 @@ if (! function_exists('getBaseUrl')) { } } - return $url . '/' . $basePath; + return strings($url . '/' . $basePath)->reduceSlashes()->trimRight('/')->toString(); } } @@ -198,7 +198,7 @@ if (! function_exists('getAbsoluteUrl')) { $url .= '/'; $url .= $_SERVER['REQUEST_URI'] ?? ''; - return $url; + return strings($url)->reduceSlashes()->trimRight('/')->toString(); } } @@ -214,7 +214,7 @@ if (! function_exists('getProjectUrl')) { $url .= '/'; $url .= FLEXTYPE_PROJECT_NAME; - return $url; + return strings($url)->reduceSlashes()->trimRight('/')->toString(); } } @@ -228,6 +228,33 @@ if (! function_exists('getUriString')) { } } +if (! function_exists('url')) { + /** + * Build URl Strings. + * + * @return string URl Strings. + */ + function url(string $string = '', string $prefix = 'base'): string + { + switch ($prefix) { + case 'project': + $url = getProjectUrl(); + break; + + case 'base': + default: + $url = getBaseUrl(); + break; + } + + $url .= '/'; + $url .= $string; + + return strings($url)->reduceSlashes()->trimRight('/')->toString(); + } +} + + if (! function_exists('redirect')) { /** * Redirect.