From b68d15342ea5b17b4e2de9bec2b52b53092fd29a Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 23 Jun 2022 19:46:49 +0300 Subject: [PATCH] feat(helpers): add `getProjectUrl` and improve `getAbsoluteUrl ` and `getBaseUrl` --- src/flextype/helpers/url.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/flextype/helpers/url.php b/src/flextype/helpers/url.php index cf3ee479..d1e0cc3c 100644 --- a/src/flextype/helpers/url.php +++ b/src/flextype/helpers/url.php @@ -119,7 +119,7 @@ if (! function_exists('getBaseUrl')) { $basePath = registry()->get('flextype.settings.base_path') ?? ''; if ($baseUrl != '') { - return $baseUrl . $basePath; + return strings($baseUrl . '/' . $basePath)->reduceSlashes()->trimRight('/')->toString(); } $getAuth = static function (): string { @@ -165,9 +165,9 @@ if (! function_exists('getBaseUrl')) { if ($url) { if ($isHttps) { - $url = 'https://' . $url . '/'; + $url = 'https://' . $url; } else { - $url = 'http://' . $url . '/'; + $url = 'http://' . $url; } } @@ -186,12 +186,29 @@ if (! function_exists('getAbsoluteUrl')) { function getAbsoluteUrl(): string { $url = getBaseUrl(); + $url .= '/'; $url .= $_SERVER['REQUEST_URI'] ?? ''; return $url; } } +if (! function_exists('getProjectUrl')) { + /** + * Get the application project url. + * + * @return string Application project url. + */ + function getProjectUrl(): string + { + $url = getBaseUrl(); + $url .= '/'; + $url .= PROJECT_NAME; + + return $url; + } +} + if (! function_exists('getUriString')) { /** * Get uri string.