src/Url.php
private static function myParse(?UrlInterface $baseUrl = null, string $url, ?SchemeInterface &$scheme = null, ?HostInterface &$host = null, ?int &$port = null, ?UrlPathInterface &$path = null, ?string &$queryString = null, ?string &$fragment = null, ?string &$error = null): bool
    {
        if ($baseUrl === null && $url === '') {
            $error = 'Url "" is empty.';

            return false;
        }

        // Split the url in its main components.
        self::mySplit($url, $schemeString, $authorityString, $pathString);

        // Parse scheme.
        if (!self::myParseScheme($baseUrl, $schemeString, $scheme, $error)) {
            $error = 'Url "' . $url . '" is invalid: ' . $error;

            return false;
        }

        // Parse authority.
        if (!self::myParseAuthority($baseUrl, $authorityString, $host, $port, $error)) {
            $error = 'Url "' . $url . '" is invalid: ' . $error;

            return false;
        }

        // Set default port if needed.
        if ($port === null) {
            $port = $scheme->getDefaultPort();
        }

        // Parse path.
        if (!self::myParsePath($baseUrl, $pathString, $path, $queryString, $fragment, $error)) {
            $error = 'Url "' . $url . '" is invalid: ' . $error;

            return false;
        }

        return true;
    }
private static function myParse(?UrlInterface $baseUrl = null, string $url, ?SchemeInterface &$scheme = null, ?HostInterface &$host = null, ?int &$port = null, ?UrlPathInterface &$path = null, ?string &$queryString = null, ?string &$fragment = null, ?string &$error = null): bool
    {
        if ($baseUrl === null && $url === '') {
            $error = 'Url "" is empty.';

            return false;
        }

        // Split the url in its main components.
        self::mySplit($url, $schemeString, $authorityString, $pathString);

        // Parse scheme.
        if (!self::myParseScheme($baseUrl, $schemeString, $scheme, $error)) {
            $error = 'Url "' . $url . '" is invalid: ' . $error;

            return false;
        }

        // Parse authority.
        if (!self::myParseAuthority($baseUrl, $authorityString, $host, $port, $error)) {
            $error = 'Url "' . $url . '" is invalid: ' . $error;

            return false;
        }

        // Set default port if needed.
        if ($port === null) {
            $port = $scheme->getDefaultPort();
        }

        // Parse path.
        if (!self::myParsePath($baseUrl, $pathString, $path, $queryString, $fragment, $error)) {
            $error = 'Url "' . $url . '" is invalid: ' . $error;

            return false;
        }

        return true;
    }
private static function myParse ( ? UrlInterface $ baseUrl = null , string $ url , ? SchemeInterface & $ scheme = null , ? HostInterface & $ host = null , ? int & $ port = null , ? UrlPathInterface & $ path = null , ? string & $ queryString = null , ? string & $ fragment = null , ? string & $ error = null ) : bool { if ( $ baseUrl === null && $ url === '' ) { $ error = 'Url "" is empty.' ; return false ; } // Split the url in its main components. self :: mySplit ( $ url , $ schemeString , $ authorityString , $ pathString ) ; // Parse scheme. if ( ! self :: myParseScheme ( $ baseUrl , $ schemeString , $ scheme , $ error ) ) { $ error = 'Url "' . $ url . '" is invalid: ' . $ error ; return false ; } // Parse authority. if ( ! self :: myParseAuthority ( $ baseUrl , $ authorityString , $ host , $ port , $ error ) ) { $ error = 'Url "' . $ url . '" is invalid: ' . $ error ; return false ; } // Set default port if needed. if ( $ port === null ) { $ port = $ scheme -> getDefaultPort ( ) ; } // Parse path. if ( ! self :: myParsePath ( $ baseUrl , $ pathString , $ path , $ queryString , $ fragment , $ error ) ) { $ error = 'Url "' . $ url . '" is invalid: ' . $ error ; return false ; } return true ; }
Tries to parse a url and returns the result or error text.

@param UrlInterface|null     $baseUrl     The base url or null if no base url is present.
@param string                $url         The url.
@param SchemeInterface|null  $scheme      The scheme if parsing was successful, undefined otherwise.
@param HostInterface|null    $host        The host if parsing was successful, undefined otherwise.
@param int|null              $port        The port if parsing was successful, undefined otherwise.
@param UrlPathInterface|null $path        The path if parsing was successful, undefined otherwise.
@param string|null           $queryString The query string if parsing was successful, undefined otherwise.
@param string|null           $fragment    The fragment if parsing was successful, undefined otherwise.
@param string|null           $error       The error text if parsing was not successful, undefined otherwise.

@return bool True if parsing was successful, false otherwise.
Tries to parse a url and returns the result or error text .