Create own base URL class which holds the whole base url business logic

This commit is contained in:
Philipp Holzer 2019-04-08 21:12:10 +02:00
parent 6ea531d2f8
commit 318a3ca785
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
16 changed files with 434 additions and 876 deletions

View file

@ -835,4 +835,26 @@ class Network
(strlen($query) ? "?".$query : '') .
(strlen($fragment) ? "#".$fragment : '');
}
/**
* @brief Switch the scheme of an url between http and https
*
* @param string $url URL
*
* @return string switched URL
*/
public static function switchScheme($url)
{
$parts = parse_url($url, PHP_URL_SCHEME);
if (!isset($parts['scheme'])) {
return $url;
}
if ($parts['scheme'] == 'http') {
$url = str_replace('http://', 'https://', $url);
} elseif ($parts['scheme'] == 'https') {
$url = str_replace('https://', 'http://', $url);
}
return $url;
}
}