Parse the url and set server parameters

@access private
@return bool
327245
private function parseUrl()
	{
		$url = parse_url($this->endpoint);

		$this->serverHost = $url['host'];
		$this->serverPort = isset($url['port']) ? $url['port'] : null;

		if (array_key_exists('scheme', $url) && $url['scheme'] == 'https') {
			$this->serverHost = 'ssl://' . $this->serverHost;
			if (!$this->serverPort) {
				$this->serverPort = 443;
			}
		}

		return TRUE;
	}
1273419
public function parseUrl()
    {
        // Checks if the key access doesn't exist or if this key is not define
        if (!array_key_exists('access', $_GET) || !isset($_GET['access'])) {
            $_GET['access'] = 'home';
        }
        // Stores the $_GET['access'] value to this page
        $this->page = $_GET['access'];

        // Cuts this page value with the exclamation point
        $access = explode('!', $this->page);

        // Attributes the first access string to this rubric
        $this->rubric = $access[0];

        // Attributes the value of this rubric to this controller
        $this->controller = $this->rubric;

        // If set, attributes the second access string to the current action method
        // if not set, attributes the string index
        $this->action = count($access) == 1 ? 'index' : $access[1];
    }
159481
public static function Parse(){
            $oThis = self::CreateInstanceIfNotExists();
            $sRoot = str_replace(array("index.php", " "), array("", "%20"), $_SERVER["SCRIPT_NAME"]);//Bugfix
            $sUri = ($sRoot != "/") ? str_replace($sRoot, "", $_SERVER["REQUEST_URI"]) : substr($_SERVER["REQUEST_URI"], 1, strlen($_SERVER["REQUEST_URI"])-1);
            $aParsedRoute = explode("/", $sUri);
            $mID = (array_key_exists(1, $aParsedRoute)) ? $aParsedRoute[1] : null;
            $sMethod = $oThis->Restful();  
            $oThis->RestParams();

            if(!$oThis->bOverloadFrontend){
                $bResult = Bootstrap::AutoLoad(((!empty($aParsedRoute[0]) && $aParsedRoute[0] != "/" ) ? strtolower(str_replace("@", "", $aParsedRoute[0])) : "main"));

                if(!$bResult)
                    Bootstrap::AutoLoad("main");
            }
            
            $sUri = preg_replace("/\?.*$/", "", $sUri);//Removendo path
            $sUri = preg_replace("/\#.*$/", "", $sUri);//Removendo path
            $bCall = false;

            $aIdent = array("int" => "\d+", "str" => "\w+", "flt" => "[\d.]+");

            foreach($oThis->aRoutes as $sRoute => $fFunc){  
                if (preg_match_all('/{(?P<field>\w+)(:((?P<type>\w{3,3})|regex\((?P<regex>.*)\)))?(:(?P<notnull>notnull))?}/i',$sRoute, $aMatches)){
                    if (preg_match('/(?P<pre>.*\w)\/\{/i',$sRoute, $aMatch)){
                        $sOk = str_replace('/', '\/', $aMatch['pre']);
                        $sRoute = str_replace($aMatch['pre'], $sOk, $sRoute);
                    } 
                    foreach ($aMatches['field'] as $iKey => $sValue) {
                        if ($aMatches['regex'][$iKey]){
                            if ($aMatches['notnull'][$iKey] == 'notnull'){
                                $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':regex('.$aMatches['regex'][$iKey].'):notnull}/i',"\/(".$aMatches['regex'][$iKey].")", $sRoute);
                            }else{
                                $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':regex('.$aMatches['regex'][$iKey].')}/i',"\/?(".$aMatches['regex'][$iKey].")?", $sRoute);                                                                                
                            }
                        }else{
                            if ($aMatches['type'][$iKey]){ 
                                if ($aMatches['notnull'][$iKey] == 'notnull'){
                                    $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':'.$aMatches['type'][$iKey].':notnull}/i',"\/(".$aIdent[$aMatches['type'][$iKey]].")", $sRoute);                                        
                                }else{
                                    $sRoute = preg_replace('/\/?{'.$aMatches['field'][$iKey].':'.$aMatches['type'][$iKey].'}/i',"\/?(".$aIdent[$aMatches['type'][$iKey]].")?", $sRoute);                                        
                                }
                            }else{
                                if ($aMatches['notnull'][$iKey] == 'notnull'){
                                    $sRoute = preg_replace('/\/{'.$aMatches['field'][$iKey].':notnull}/i',"\/([^\/]*)", $sRoute);                                        
                                }else{
                                    $sRoute = preg_replace("/\/?{".$aMatches['field'][$iKey]."}/", "\/?([^\/]*)?", $sRoute);                                                                                            
                                }
                            }
                        } 
                    }
                }
                else{
                    $sRoute = str_replace('/', '\/', $sRoute);
                }                    
                
                if(preg_match_all("/^".$sRoute."\/?$/i", $sMethod."_".$sUri, $aMatches)){
                    $aParams = array();
                    foreach($aMatches as $iKey => $aResult){
                        if($iKey > 0){
                            $aParams[] = $aResult[0];
                        }
                    }

                    $bCall = true; 
                    Storage::Set("route.request", $sRoute);

                    if(is_array($fFunc)){
                        if(is_array($fFunc[1]))
                            $aParams = array_merge($fFunc[1], $aParams);
                        else
                            $aParams = array_merge(array($fFunc[1]), $aParams);

                        call_user_func_array($fFunc[0], $aParams);
                    }
                    else{
                        call_user_func_array($fFunc, $aParams);
                    }

                    break;
                }              
            }        
            
            if(array_key_exists("__dynamicroute", $oThis->aRoutes) && !$bCall)
                call_user_func($oThis->aRoutes["__dynamicroute"]);  
            else
                Output::SendHTTPCode(404);
        }
1229616
public static function parseUrl($url)
	{
		$result = false;

		// Build arrays of values we need to decode before parsing
		$entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%24', '%2C', '%2F', '%3F', '%23', '%5B', '%5D');
		$replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "$", ",", "/", "?", "#", "[", "]");

		// Create encoded URL with special URL characters decoded so it can be parsed
		// All other characters will be encoded
		$encodedURL = str_replace($entities, $replacements, urlencode($url));

		// Parse the encoded URL
		$encodedParts = parse_url($encodedURL);

		// Now, decode each value of the resulting array
		if ($encodedParts)
		{
			foreach ($encodedParts as $key => $value)
			{
				$result[$key] = urldecode(str_replace($replacements, $entities, $value));
			}
		}

		return $result;
	}
965354
private function parseCgiParameters() {
		
		if (FALSE===strpos($this->url, '?')) {
			return;
		}
			
		$temp = explode('?', $this->url);
		$this->url = $temp[0];
		
		if (!array_key_exists(1, $temp)) {
			return;
		}
			
		// adds to $this->params
		$couples = explode('&', $temp[1]);
		
		foreach ($couples as $c) {
			
			$var = explode('=', $c);
			
			if (array_key_exists(1, $var)) {
				list ($key, $value) = $var;
				$this->setParam($key, $value);
			}
			
		}
		
	}
33115
protected function parse_request() {
        // Retrieve and clean the POST/GET parameters from the parameters specific to the server.
        parent::set_web_service_call_settings();

        if ($this->authmethod == WEBSERVICE_AUTHMETHOD_USERNAME) {
            $this->username = optional_param('wsusername', null, PARAM_RAW);
            $this->password = optional_param('wspassword', null, PARAM_RAW);

            if (!$this->username or !$this->password) {
                // Workaround for the trouble with & in soap urls.
                $authdata = get_file_argument();
                $authdata = explode('/', trim($authdata, '/'));
                if (count($authdata) == 2) {
                    list($this->username, $this->password) = $authdata;
                }
            }
            $this->serverurl = new moodle_url('/webservice/soap/simpleserver.php/' . $this->username . '/' . $this->password);
        } else {
            $this->token = optional_param('wstoken', null, PARAM_RAW);

            $this->serverurl = new moodle_url('/webservice/soap/server.php');
            $this->serverurl->param('wstoken', $this->token);
        }

        if ($wsdl = optional_param('wsdl', 0, PARAM_INT)) {
            $this->wsdlmode = true;
        }
    }
1373667
private function processParameters()
    {
        $parameters = $this->parameters;
        $string = $this->query;

        $string = str_replace('[:', '[;;', $string);

        $parameters = array_filter($parameters, function ($value) use (& $parameters, & $string)
        {
            $key = key($parameters);
            next($parameters);

            if (is_numeric($value))
            {
                $string = str_replace(":$key", $value, $string);
                return false;
            }

            else
            {
                $string = str_replace(":$key", '{' . $key . '}', $string);
                return true;
            }
        });

        $string = str_replace('[;;', '[:', $string);

        $this->query = $string;
        return $parameters;
    }
720828
private function parseProxy()
    {
        if($this->request->getAttribute('useProxy', false))
        {
            $type = $this->request->getAttribute('proxy.type');
            switch($type)
            {
                case 'http':
                    $this->settings['http_proxy_host'] = $this->request->getAttribute('proxy.server');
                    $this->settings['http_proxy_port'] = $this->request->getAttribute('proxy.port');
                    $this->settings['http_proxy_user'] = $this->request->getAttribute('proxy.username', '');
                    $this->settings['http_proxy_password'] = $this->request->getAttribute('proxy.password', '');
                    break;
                case 'socks5':
                    $this->settings['socks5_host'] = $this->request->getAttribute('proxy.server');
                    $this->settings['socks5_port'] = $this->request->getAttribute('proxy.port');
                    $this->settings['socks5_username'] = $this->request->getAttribute('proxy.username', '');
                    $this->settings['socks5_password'] = $this->request->getAttribute('proxy.password', '');
                    break;
            }
        }
    }
657379
protected function parseUrlParams($url_params)
    {
        if ($url_params != '#' && (is_array($url_params) || (strpos($url_params, 'http') !== 0 && strpos($url_params, '/') !== 0))) {
            if (!is_array($url_params))
                $url_params = array($url_params);
            $url_to = Rails::application()->router()->urlFor($url_params, true);
        } else {
            $url_to = $url_params;
        }
        return $url_to;
    }
663868
static function parse_url_params($url)
    {
        try {
            $parse = parse_url($url);
            $query = '';
            if (isset($parse['query'])) {
                $query .= $parse['query'];
            }
            if (isset($parse['fragment'])) {
                if (empty($query)) {
                    $query = $parse['fragment'];
                } else {
                    $query .= '&' . $parse['fragment'];
                }
            }
            $queryParts = explode('&', $query);
            $params = array();
            foreach ($queryParts as $param) {
                $item = explode('=', $param);
                $params[$item[0]] = $item[1];
            }
            return $params;
        } catch (\Exception $e) {
            throw $e;
        }
    }
1140930
private function parseSSL()
    {
        if($this->request->getAttribute('isVerifyCA', false))
        {
            $this->settings['ssl_verify_peer'] = true;
            $caCert = $this->request->getAttribute('caCert');
            if(null !== $caCert)
            {
                $this->settings['ssl_cafile'] = $caCert;
            }
        }
        else
        {
            $this->settings['ssl_verify_peer'] = false;
        }
        $certPath = $this->request->getAttribute('certPath', '');
        if('' !== $certPath)
        {
            $this->settings['ssl_cert_file'] = $certPath;
        }
        $keyPath = $this->request->getAttribute('keyPath' , '');
        if('' !== $keyPath)
        {
            $this->settings['ssl_key_file'] = $keyPath;
        }
    }
1096724
public function parse()
    {
        preg_match_all("#\{(\w+)\}#", $this->uri, $params);
        $replace = [];

        foreach ($params[1] as $param) {
            $replace['{'.$param.'}'] = '(?<'.$param.'>'. (isset($this->filters[$param]) ? $this->filters[$param] : '[a-zA-Z+0-9-.]+') .')';
        }

        $this->parsedRoute = str_replace(array_keys($replace), array_values($replace), $this->uri);
    }
154740
public function parseUri()
    {
        $uri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
        $uri = str_replace(['{', '}'], '', urldecode($uri));
        $extDir = dirname(dirname($_SERVER['SCRIPT_NAME']));
        $uri = str_replace($extDir, '', $uri);
        $uri = rtrim($uri, '/');
        $uri = empty($uri) ? '/' : $uri;
        $serverRequestMethod = $_SERVER['REQUEST_METHOD'];
        $params = $GLOBALS['_'.$serverRequestMethod];
        if(!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
            $https = true;
        }
        else {
            $https = false;
        }
        $host = $_SERVER['HTTP_HOST'].str_replace('\\', '/', $extDir);
        $ip = $_SERVER['REMOTE_ADDR'];
        
        if($serverRequestMethod === 'POST') {
            $params = ['GET' => $_GET, 'POST' => $params];
        }
        else {
            $params = ['GET' => $params, 'POST' => []];
        }

        return ['uri' => $uri, 'params' => $params, 'method' => $serverRequestMethod, 'https' => $https, 'host' => $host, 'ip' => $ip];
    }
861227
protected function parseParameter()
    {
        list ($mode, $width, $height, $gravity, $background) = array_pad(
            preg_split(
                '%/%',
                $this->input['parameter'],
                -1,
                PREG_SPLIT_NO_EMPTY
            ),
            5,
            null
        );

        return $this->setParameterValues(
            (int)$mode,
            ((int)$mode !== 1 && (int)$mode !== 2) ? $this->getIntVal($width) : (int)$this->getIntVal($width),
            ((int)$mode !== 1 && (int)$mode !== 2) ? $this->getIntVal($height) : (int)$this->getIntVal($height),
            $this->getIntVal($gravity),
            $background
        );
    }
86952
public function parse() {
        $name_without_parens = preg_replace('/[{}]/', '', $this->full_name);

        $parts = explode('|', $name_without_parens);
        $name_without_pipes = trim($parts[0]);

        $parts = explode('::', $name_without_pipes);
        $name_without_case_keys = trim($parts[0]);
        array_shift($parts);
        $this->case_keys = array_map('trim', $parts);

        $parts = explode(':', $name_without_case_keys);
        $this->short_name = trim($parts[0]);
        array_shift($parts);
        $this->context_keys = array_map('trim', $parts);

        $this->separator = (strpos($this->full_name,'||') !== false) ? '||' : '|';

        $this->parameters = array();
        $parts = explode($this->separator, $name_without_parens);
        if (count($parts) > 1) {
            $parts = explode(',', $parts[1]);
            foreach($parts as $part) {
                array_push($this->parameters, trim($part));
            }
        }
    }
1364630
public function parseUri()
    {
        $uri = (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null);

        if(isset($uri))
        {
            $uri = '/' . ltrim(trim($uri), '/');
            $uri = filter_var($uri, FILTER_SANITIZE_URL);

            return $uri;
        }
        else
        {
            throw new Exception("Error parsing URI please check your URI.", 1);
        }
    }
858478
protected function parse(): void
    {
        // add the root node
        $this->root = new HtmlNode('root');
        $activeNode = $this->root;
        while ( ! is_null($activeNode)) {
            $str = $this->content->copyUntil('<');
            if ($str == '') {
                $info = $this->parseTag();
                if ( ! $info['status']) {
                    // we are done here
                    $activeNode = null;
                    continue;
                }

                // check if it was a closing tag
                if ($info['closing']) {
                    $foundOpeningTag  = true;
                    $originalNode     = $activeNode;
                    while ($activeNode->getTag()->name() != $info['tag']) {
                        $activeNode = $activeNode->getParent();
                        if (is_null($activeNode)) {
                            // we could not find opening tag
                            $activeNode = $originalNode;
                            $foundOpeningTag = false;
                            break;
                        }
                    }
                    if ($foundOpeningTag) {
                        $activeNode = $activeNode->getParent();
                    }
                    continue;
                }

                if ( ! isset($info['node'])) {
                    continue;
                }

                /** @var AbstractNode $node */
                $node = $info['node'];
                $activeNode->addChild($node);

                // check if node is self closing
                if ( ! $node->getTag()->isSelfClosing()) {
                    $activeNode = $node;
                }
            } else if ($this->options->whitespaceTextNode ||
                trim($str) != ''
            ) {
                // we found text we care about
                $textNode = new TextNode($str, $this->options->removeDoubleSpace);
                $activeNode->addChild($textNode);
            }
        }
    }