Validate a connection to the base URI

@param string $baseUri
@return boolean
184918
private function validateConnection($baseUri) {
        $parts = parse_url($baseUri);
        $host = $parts['host'];
        $port = isset($parts['port']) ? $parts['port'] : ($parts['scheme'] === 'https' ? 443 : 80);

        set_error_handler(function () {
            return true;
        });

        $resource = fsockopen($host, $port);
        restore_error_handler();

        if ($resource === false) {
            // Can't connect
            return false;
        }

        // Connection successful, close connection
        fclose($resource);

        return true;
    }
26003
public static function ResolveUri( $relative, $baseUri )
	{
		if ( $relative instanceof Undefined )
		{
			return Undefined::getValue();
		}

		$rel = CoreFuncs::NormalizeSpace( $relative . "" );

		if ( ExtFuncs::isAbsoluteUrl( $rel ) )
		{
			return $rel;
		}

		if ( ! ExtFuncs::validateUri( $rel ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORG0002", Resources::FORG0002, $rel );
		}

		if ( $baseUri instanceof Undefined )
		{
			return Undefined::getValue();
		}

		$bsUri = CoreFuncs::NormalizeSpace( $baseUri . "" );

		if ( ! ExtFuncs::isAbsoluteUrl( $bsUri ) || ! ExtFuncs::validateUri( $bsUri ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORG0002", Resources::FORG0002, $rel );
		}

		if ( $bsUri == "" )
		{
			return new AnyUriValue( $rel );
		}

		try
		{
			$url = ExtFuncs::InternetCombineUrl( $bsUri, $rel );
			if ( ! ExtFuncs::validateUri( $url ) )
			// if ( ! filter_var( $url, FILTER_VALIDATE_URL ) )
			{
				throw XPath2Exception::withErrorCode( "FORG0009", Resources::FORG0009 );
			}
			return new AnyUriValue( $url );
		}
		catch ( UriFormatException $ex )
		{
		    throw XPath2Exception::withErrorCode( "FORG0009", Resources::FORG0009 );
		}
	}
1264519
public function isActive( $requestUri = null )
    {
        $uri = rawurldecode( preg_replace( '/[\\?#].*$/', '', (string) $this->getUri() ) );

        if ( empty( $uri ) || '/' !== $uri[0] )
        {
            return false;
        }

        if ( null === $requestUri )
        {
            if ( null === $this->requestUri )
            {
                $this->requestUri = $this->getServiceLocator()
                                         ->get( 'Request' )
                                         ->getRequestUri();

                $this->requestUri = preg_replace(
                    '/\\?.*$/', '',
                    $this->requestUri
                );
            }

            $requestUri = $this->requestUri;
        }
        else
        {
            $requestUri = preg_replace(
                '/[\\?#].*$/', '',
                (string) $requestUri
            );
        }

        $requestUri = rawurldecode( $requestUri );

        return $requestUri === $uri || (
            mb_strlen( $requestUri ) > mb_strlen( $uri ) &&
            mb_substr( $requestUri, 0, mb_strlen( $uri ) + 1 ) === ( $uri . '/' )
        );
    }
1124719
private function parseUri($uri)
    {
        $parts = parse_url($uri);

        if (false === $parts) {
            throw new \InvalidArgumentException(
                'The source URI string appears to be malformed'
            );
        }

        $this->scheme    = isset($parts['scheme'])   ? $this->filterScheme($parts['scheme']) : '';
        $this->userInfo  = isset($parts['user'])     ? $parts['user']     : '';
        $this->host      = isset($parts['host'])     ? $parts['host']     : '';
        $this->port      = isset($parts['port'])     ? $parts['port']     : null;
        $this->path      = isset($parts['path'])     ? $this->filterPath($parts['path']) : '';
        $this->query     = isset($parts['query'])    ? $this->filterQuery($parts['query']) : '';
        $this->fragment  = isset($parts['fragment']) ? $this->filterFragment($parts['fragment']) : '';

        if (isset($parts['pass'])) {
            $this->userInfo .= ':' . $parts['pass'];
        }
    }
784094
public function setBaseUrl($uri)
    {
        if (is_string($uri)) {
            $this->baseUrl = Uri::createFromString($uri);
        } else {
            $this->baseUrl = $uri;
        }
        return $this;
    }
1147578
public function base()
    {
        if (!$this->validate()) {
            throw new \InvalidArgumentException("Invalid URI: $this->uri");
        }
        $parts = [
            'scheme' => parse_url($this->uri, PHP_URL_SCHEME),
            'host' => parse_url($this->uri, PHP_URL_HOST),
        ];
        $parts['port'] = is_int($port = parse_url($this->uri, PHP_URL_PORT)) ? $port : getservbyname($parts['scheme'], 'tcp');
        return strtolower($parts['scheme'] . '://' . $parts['host'] . ':' . $parts['port']);
    }
16451
public function base_uri(){
    	$uri = $this->uri();
		if (($strpos = strpos($uri, '?')) !== false) 
			$uri = substr($uri, 0, $strpos);
		return $uri;
    }
941373
private function validateRequestURI(&$requestURI)
    {
        if ($requestURI != '/' && substr($requestURI, -1) == '/') {
            $url = rtrim($requestURI, '/');

            if (php_sapi_name() === 'cli') {
                exit("Please ensure the URL you typed in does not have a trailing backslash.\n");
            }

            header("Location: " . $url);
            exit();
        }
    }
974464
public function withBasePath($basePath)
    {
        if (!is_string($basePath)) {
            throw new InvalidArgumentException('Uri path must be a string');
        }
        if (!empty($basePath)) {
            $basePath = '/' . trim($basePath, '/');
        }
        $clone = clone $this;

        if ($basePath !== '/') {
            $clone->basePath = Validator::checkPath($basePath);
        }

        return $clone;
    }
996661
public function valid()
        {
            // Return true if and only if all parts of the URI have passed validation
            return $this->validateUsername()
               && $this->validatePassword()
               && $this->validateHost()
               && $this->validatePort()
               && $this->validatePath()
               && $this->validateQuery()
               && $this->validateFragment();
        }
46720
public static function isValidRelative(string $url, UrlInterface $baseUrl): bool
    {
        try {
            return self::myParse($baseUrl, $url);
        } catch (UrlPathLogicException $exception) {
            return false;
        }
    }
696718
public function setBaseUri($uri) : self
    {
        $this->baseUri = $uri instanceof Uri ? $uri : new Uri($uri);

        return $this;
    }
1007029
public function resolve($uri, $baseUri = null)
    {
        $components = $this->parse($uri);
        $path = $components['path'];

        if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) {
            return $uri;
        }

        $baseComponents = $this->parse($baseUri);
        $basePath = $baseComponents['path'];

        $baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath);

        return $this->generate($baseComponents);
    }
1356525
public function setCurrentURI($uri) {
        if(is_string($uri) && !empty(trim($uri))){
            $this->currentURI = $uri;
            $this->currentArray = Levels::getCurrent($this->navigation, $this->currentURI);
        }
        else{
            throw new InvalidArgumentException(
                '$uri must be a valid string when seting the current URI'
            );
        }
        return $this;
    }
891526
public static boolean validateResource(URI uri) {
        return uri != null && uri.getPort() != -1 && uri.getHost() != null;
    }
602062
public void setBaseUri(final String baseUri) {
        Validate.notNull(baseUri);

        traverse(new NodeVisitor() {
            public void head(Node node, int depth) {
                node.doSetBaseUri(baseUri);
            }

            public void tail(Node node, int depth) {
            }
        });
    }
1241209
public function getUri()
    {
        $uri = rtrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/');
        $baseUri = $this->getBaseUri();
        $uri = str_replace($baseUri, '', $uri)?: '/';

        return $uri;
    }