Bramus\MCS\Scanner::setRootUrl PHP Method

setRootUrl() private method

Sets the root URL of the website to scan
private setRootUrl ( string $rootUrl, boolean $limitToPath = true )
$rootUrl string
$limitToPath boolean
    private function setRootUrl($rootUrl, $limitToPath = true)
    {
        // If the rootUrl is *, it means that we'll pass in some URLs manually
        if ($rootUrl == '*') {
            $this->rootUrl = $rootUrl;
            return;
        }
        // Make sure the rootUrl is parse-able
        $urlParts = parse_url($rootUrl);
        if (!$urlParts || !isset($urlParts['scheme']) || !isset($urlParts['host'])) {
            $this->logger->addEmergency('Invalid rootUrl!');
            throw new Exception('Invalid rootUrl!');
        }
        // Force trailing / on rootUrl, it's easier for us to work with it
        if (substr($rootUrl, -1) != '/') {
            $rootUrl .= '/';
        }
        // store rootUrl
        $this->rootUrl = strstr($rootUrl, '?') ? substr($rootUrl, 0, strpos($rootUrl, '?')) : $rootUrl;
        // store rootUrl without queryString
        // If we need to limit to the path of the URL (viz. at first run): take that one into account
        // Otherwise keep the already set path
        $this->rootUrlBasePath = $urlParts['scheme'] . '://' . $urlParts['host'] . ($limitToPath ? $urlParts['path'] : $this->rootUrlParts['path']);
        if (!$limitToPath) {
            $this->logger->addNotice('Updated rootUrl to ' . $this->rootUrl);
            $this->logger->addNotice('Updated rootUrlBasePath to ' . $this->rootUrlBasePath);
        }
        // store urlParts
        $this->rootUrlParts = $urlParts;
    }