Validates a given URI

Executes the validator using the current parameters and returns a Response
object on success.

@param string $uri The address to the page to validate ex: http://example.com/

@return Response object HTMLValidator\Response
198118
public function validateUri($uri)
    {
        $query = http_build_query(array_merge(
            $this->getOptions()->buildOptions(),
            array('uri' => $uri)
        ));

        $context = stream_context_create(array(
            'http' => array(
                'method' => 'GET',
                'header' => 'User-Agent: HTMLValidator',
            )
        ));

        $data = $this->sendRequest($this->validatorUri . '?' . $query, $context);

        return $this->parseSOAP12Response($data);
    }
305183
private function parse($uri)
	{
		$parts = parse_url($uri);

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

		//	special handling of mailto: scheme
		if (($parts['scheme'] ?? null) === 'mailto')
		{
			if (isset($parts['host']) || isset($parts['user']) || isset($parts['pass']) || isset($parts['fragment']) || isset($parts['query']) || isset($parts['port']) || empty($parts['path']) || $parts['path'][0] === '/')
				throw new \InvalidArgumentException("The source email address `{$uri}` appears to be malformed");

			$parts = parse_url('mailto://' . $parts['path']);	//	we 'fool' the parser by adding '//' before the email address, this allows parse_url() to detect the 'authority` components (user@domain)

			if ($parts === false)
				throw new \InvalidArgumentException("The source email address `{$uri}` appears to be malformed");
		}

		$this->fromArray($parts);
	}
123608
protected static function setURI($uri){
        if(!is_string($uri)){
            throw new InvalidArgumentException(
                '$uri must be a string or null'
            );
        }
        self::$uri = filter_var($uri, FILTER_SANITIZE_URL);
    }
1058112
public function getUri($uri) {
        $curieSeperator = ':';

        if (preg_match('/http(s*)\:\/\//', $uri) == false) {
            if (strpos($uri, $curieSeperator) !== false) {
                list($prefix, $action) = explode($curieSeperator, $uri);
                
                if(isset($this->WAMP->prefixes[$prefix]) === true){
                  return $this->WAMP->prefixes[$prefix] . '#' . $action;
                }
            }
        }

        return $uri;
    }
738981
public function match($uri)
    {
        foreach ($this->routes as $route) {
            $result = $route->match($uri);

            if ($result == true) {
                return $route;
            }
        }
    }
404304
public function setUri($uri)
    {
        if ($uri instanceof Zend_Uri_Http) {
            // clone the URI in order to keep the passed parameter constant
            $uri = clone $uri;
        } elseif (is_string($uri)) {
            $uri = Zend_Uri::factory($uri);
        }

        if (!$uri instanceof Zend_Uri_Http) {
            /** @see Zend_Http_Client_Exception */

            throw new Zend_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
        }

        // Set auth if username and password has been specified in the uri
        if ($uri->getUsername() && $uri->getPassword()) {
            $this->setAuth($uri->getUsername(), $uri->getPassword());
        }

        // We have no ports, set the defaults
        if (! $uri->getPort()) {
            $uri->setPort(($uri->getScheme() == 'https' ? 443 : 80));
        }

        $this->uri = $uri;

        return $this;
    }
314284
protected function fromString($uri)
    {
        if (empty($uri)) {
            return $this;
        }

        $this->fromArray(parse_url($uri));

        return $this;
    }
788748
public static function isValid(string $uri): bool {
        try {
            new self($uri);
        } catch (InvalidUriException $e) {
            return false;
        }

        return true;
    }
1140409
public function validate(string ...$urls): ResultInterface
    {
        $httpUrls = array_filter($urls, function (string $url): bool {
            return 'https' !== wp_parse_url($url, PHP_URL_SCHEME);
        });

        return $this->report(...$httpUrls);
    }
161615
private function isValidString($uri)
    {
        if (preg_match('/^[\\x00-\\x7F]*$/', $uri)) {
            return true;
        } elseif ($this->mode === self::MODE_RFC3986) {
            return false;
        }

        // Validate UTF-8 via regular expression to avoid mbstring dependency
        $pattern =
            '/^(?>
                [\x00-\x7F]+                       # ASCII
              | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
              |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding over longs
              | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
              |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
              |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
              | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
              |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
            )*$/x';

        return (bool) preg_match($pattern, $uri);
    }
337154
protected function httpGet($uri)
    {
        $results = [];
        // Start requesting at page 1
        $page = 1;
        $pageSize = 100;
        // We dont know how many pages there are, so assume 1 until we know
        $pagecount = 1;
        while ($page <= $pagecount) {
            //echo('fetching page '.$page.' of '.$pagecount.' current result size is '.count($results).PHP_EOL);
            $this->log[] = [
                        'request' => [
                                    'method' => 'GET',
                                    'uri'    => $uri.'?page='.$page.'&per_page='.$pageSize,
                                    ],
                        ];
            $response = \Httpful\Request::get($uri.'?page='.$page)
                                                    ->basicAuth($this->username, $this->password)
                                                    ->expectsType(\Httpful\Mime::JSON)
                                                    ->parseWith(function ($body) {
                                                        return \Metaclassing\Utility::decodeJson($body);
                                                    })
                                                    ->send()
                                                    ->body;
            $this->log[count($this->log) - 1]['response'] = $response;

            $resultKey = '';
            if (isset($response['zones'])) {
                $resultKey = 'zones';
            }
            if (isset($response['resource_records'])) {
                $resultKey = 'resource_records';
            }
            if (!$resultKey) {
                throw new \Exception('Unhandled results key, check dns client logs for details');
            }
            foreach ($response[$resultKey] as $result) {
                array_push($results, $result);
            }
            // Now that we KNOW the pagecount, update that and increment our page counter
            if (isset($response['total_count'])) {
                $totalResults = $response['total_count'];
                $pagecount = ceil($totalResults / $pageSize);
            }
            // And get the next page ready for the next request
            $page++;
        }

        return $results;
    }
728198
public function handle($uri = null)
    {
        try {
            $returnedResponse = parent::handle($uri);
            return $this->handleWeb($returnedResponse);
        } catch (Throwable $e) {
            /** @noinspection PhpUnhandledExceptionInspection */
            return $this->handleException($e);
        }
    }
1217686
public static function getAbsoluteUri(string $uri = null) : string
    {
        $uri = new self($uri);

        return $uri->get(false);
    }
1328703
public function options(string $uri)
    {
        $request = $this->getRequest($uri)
            ->setMethod('OPTIONS');

        return $this->send($request);
    }
1003181
public function internalRedirect($uri)
    {
        if (is_string($uri)) {

            // make a new URI instance, then make a new request
            $uri = $this->request->getUri()->withPath($uri);
            return $this->request->withUri($uri);

        } elseif ($uri instanceof UriInterface) {

            // get a new request with the specified URI instance
            return $this->request->withUri($uri);

        } else {

            // bad $uri value
            throw new InvalidArgumentException(
                'URI should be a string or instance of Psr\Http\Message\UriInterface'
            );

        }
    }
617372
public function parse($uri)
    {
        preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);

        $components = array();
        if (5 < count($match)) {
            $components =  array(
                'scheme'    => $match[2],
                'authority' => $match[4],
                'path'      => $match[5]
            );
        }
        if (7 < count($match)) {
            $components['query'] = $match[7];
        }
        if (9 < count($match)) {
            $components['fragment'] = $match[9];
        }

        return $components;
    }
437383
protected function get($uri=null)
    {
        if (!is_null($uri)) {
            if (!($this->getCrudService()->isInScope($uri))) {
                throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
            }
            return $this->getCrudService()->get($uri);
        } else {
            return $this->getCrudService()->getAll();
        }
    }