Nabble\SemaltBlocker\Domainparser::parseUrl PHP Метод

parseUrl() приватный статический Метод

Checks an URL for validity, and punycode encode the returned component.
private static parseUrl ( string $url, integer $component ) : string | false
$url string
$component integer
Результат string | false
    private static function parseUrl($url, $component)
    {
        if (!isset(self::$cache[$url]['url'])) {
            // Strip protocol
            $scheme = parse_url($url, PHP_URL_SCHEME);
            $url = str_replace($scheme . '://', '', $url);
            $url = str_replace($scheme . ':', '', $url);
            // Punycode encode domain
            $host = parse_url('http://' . $url, PHP_URL_HOST);
            $punycode = new Punycode();
            $url = str_replace($host, $punycode->encode($host), $url);
            // Add back normalized protocol
            $url = 'http://' . $url;
            // Remove all illegal characters from a url
            $url = filter_var($url, FILTER_SANITIZE_URL);
            // Sanity check
            if (($check = filter_var($url, FILTER_VALIDATE_URL)) === false) {
                $url = false;
            }
            self::$cache[$url]['url'] = $url;
        }
        return parse_url(strtolower(self::$cache[$url]['url']), $component);
    }