yii\helpers\BaseUrl::ensureScheme PHP Method

ensureScheme() public static method

If URL is relative or scheme is not string, normalization is skipped.
Since: 2.0.11
public static ensureScheme ( string $url, string $scheme ) : string
$url string the URL to process
$scheme string the URI scheme used in URL (e.g. `http` or `https`). Use empty string to create protocol-relative URL (e.g. `//example.com/path`)
return string the processed URL
    public static function ensureScheme($url, $scheme)
    {
        if (static::isRelative($url) || !is_string($scheme)) {
            return $url;
        }
        if (substr($url, 0, 2) === '//') {
            // e.g. //example.com/path/to/resource
            return $scheme === '' ? $url : "{$scheme}:{$url}";
        }
        if (($pos = strpos($url, '://')) !== false) {
            if ($scheme === '') {
                $url = substr($url, $pos + 1);
            } else {
                $url = $scheme . substr($url, $pos);
            }
        }
        return $url;
    }