Main method for parsing a query string.
Finds search paramters, partial response fields, limits, and offsets.

@return void
485209
protected function parseRequest()
    {
        if ($this->customParams === false) {
            // pull various supported inputs from post
            $request = $this->di->get('request');

            // only process if it is a get
            if ($request->isGet() == false) {
                return;
            }
        } else {
            $_REQUEST = $_GET = $this->customParams;
            $request = $this->di->get('request');
        }

        // simple stuff first
        $with = $request->get('with', "string", null);
        $include = $request->get('include', "string", null);
        if (!is_null($with)) {
            $this->suppliedWith = $with;
        } elseif (!is_null($include)) {
            $this->suppliedWith = $include;
        }

        // load possible sort values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('sort', "string", null) != null) {
            $this->suppliedSort = $request->get('sort', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sort_field', "string", null) != null) {
            $this->suppliedSort = $request->get('sort_field', "string", null);
            $this->isPager = true;
        } elseif ($request->get('sortField', "string", null) != null) {
            $this->suppliedSort = $request->get('sortField', "string", null);
            $this->isPager = true;
        }

        // prep for the harder stuff
        // ?page=1&perPage=25&orderAscending=false

        // load possible limit values in the following order
        // be sure to mark this as a paginated result set
        if ($request->get('limit', "string", null) != null) {
            $this->suppliedLimit = $request->get('limit', "string", null);
            $this->isPager = true;
        } elseif ($request->get('per_page', "string", null) != null) {
            $this->suppliedLimit = $request->get('per_page', "string", null);
            $this->isPager = true;
        } elseif ($request->get('perPage', "string", null) != null) {
            $this->suppliedLimit = $request->get('perPage', "string", null);
            $this->isPager = true;
        }

        // look for string that means to show all records
        if ($this->isPager) {
            if ($this->suppliedLimit == 'all') {
                $this->suppliedLimit = 9999999999;
            }
        }

        // load offset values in the following order
        // Notice that a page is treated differently than offset
        // $this->offset = ($offset != null) ? $offset : $this->offset;
        if ($request->get('offset', "int", null) != null) {
            $this->suppliedOffset = $request->get('offset', "int", null);
            $this->isPager = true;
        } elseif ($request->get('page', "int", null) != null) {
            $this->suppliedOffset = ($request->get('page', "int", null) - 1) * $this->suppliedLimit;
            $this->isPager = true;
        }

        // Check if we pass the count parameter with whatever value
        if ($request->has('count')) {
            $this->isCount = true;
        }

        // http://jsonapi.org/format/#fetching
        $this->parseSearchParameters($request);
    }
1240777
public function do_search()
    {
        $query = (string) $this->request->request('query');

        $ipl = new PageList();
        $aksearch = false;
        $akIDs = $this->request->request('akID');
        if (is_array($akIDs)) {
            foreach ($akIDs as $akID => $req) {
                $fak = CollectionAttributeKey::getByID($akID);
                if (is_object($fak)) {
                    $type = $fak->getAttributeType();
                    $cnt = $type->getController();
                    $cnt->setAttributeKey($fak);
                    $cnt->searchForm($ipl);
                    $aksearch = true;
                }
            }
        }

        if ($this->request->request('month') !== null && $this->request->request('year') !== null) {
            $year = @(int) ($this->request->request('year'));
            $month = abs(@(int) ($this->request->request('month')));
            if (strlen(abs($year)) < 4) {
                $year = (($year < 0) ? '-' : '') . str_pad(abs($year), 4, '0', STR_PAD_LEFT);
            }
            if ($month < 12) {
                $month = str_pad($month, 2, '0', STR_PAD_LEFT);
            }
            $daysInMonth = date('t', strtotime("$year-$month-01"));
            $dh = Core::make('helper/date');
            /* @var $dh \Concrete\Core\Localization\Service\Date */
            $start = $dh->toDB("$year-$month-01 00:00:00", 'user');
            $end = $dh->toDB("$year-$month-$daysInMonth 23:59:59", 'user');
            $ipl->filterByPublicDate($start, '>=');
            $ipl->filterByPublicDate($end, '<=');
            $aksearch = true;
        }

        if ($query === '' && $aksearch === false) {
            return false;
        }

        if ($query !== '') {
            $ipl->filterByKeywords($query);
        }

        $search_paths = $this->request->request('search_paths');
        if (is_array($search_paths)) {
            foreach ($search_paths as $path) {
                if ($path === '') {
                    continue;
                }
                $ipl->filterByPath($path);
            }
        } elseif ($this->baseSearchPath != '') {
            $ipl->filterByPath($this->baseSearchPath);
        }

        $cak = CollectionKey::getByHandle('exclude_search_index');
        if (is_object($cak)) {
            $ipl->filterByExcludeSearchIndex(false);
        }

        $pagination = $ipl->getPagination();
        $results = $pagination->getCurrentPageResults();

        $this->set('query', $query);
        $this->set('results', $results);
        $this->set('do_search', true);
        $this->set('searchList', $ipl);
        $this->set('pagination', $pagination);
    }
471299
protected function parse()
    {
        $parseOptions = true;
        $this->parsed = $this->tokenPairs;
        while (null !== $tokenPair = \array_shift($this->parsed)) {
            // token is what you'd expect. rest is the remainder of the input
            // string, including token, and will be used if this is a code arg.
            list($token, $rest) = $tokenPair;

            if ($parseOptions && '' === $token) {
                $this->parseShellArgument($token, $rest);
            } elseif ($parseOptions && '--' === $token) {
                $parseOptions = false;
            } elseif ($parseOptions && 0 === \strpos($token, '--')) {
                $this->parseLongOption($token);
            } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
                $this->parseShortOption($token);
            } else {
                $this->parseShellArgument($token, $rest);
            }
        }
    }
889737
protected function parseFilter()
    {
        if (! $params = $this->getParams()) {
            return;
        }

        foreach ($params as $key => $value) {
            if ($this->isEloquentBuilder() && Str::contains($key, '~')) {
                $this->filterRelation($key, $value);
            } else {
                $this->filter($key, $value);
            }
        }
    }
1245000
private function searchQuery(): string
    {
        $url = \parse_url($this->app->utilities->page->URL('full'));
        \parse_str(($url['query'] ?? ''), $query_params);

        return $query_params['s'] ?? '';
    }
908332
public static function build_query_string()
	{
		$params = array();

		foreach (func_get_args() as $arg)
		{
			$arg = is_array($arg) ? $arg : array($arg => '1');

			$params = array_merge($params, $arg);
		}

		return http_build_query($params);
	}
963903
protected function parse()
    {
        $this->parseParam('sort');
        $this->parseParam('fields');
        $this->parseParam('limit');
        if ($this->isEloquentBuilder()) {
            $this->parseParam('with');
        }
        $this->parseFilter();
    }
873954
private function parse()
    {
        $this->parameters   = [];
        $this->pathSegments = [];
        $parsedUrl          = parse_url($this->returnValue);
        foreach ($parsedUrl as $key => $value) {
            if ($key == 'query') {
                parse_str($value, $this->parameters);
            } elseif ($key == 'path') {
                $this->pathSegments = ($value) ? explode('/', ltrim($value, '/')) : [];
            } else {
                $this->{$key} = $value;
            }
        }
        return $this;
    }
1320593
public function buildQueryStringParams()
    {
        $params = [];
        if ($this->limit > 0) {
            $params['page']['limit'] = $this->limit;
        }
        if ($this->offset > 0) {
            $params['page']['offset'] = $this->offset;
        }
        if ($this->sort) {
            $params['sort'] = $this->sort;
        }
        if ($this->filter) {
            $params['filter'] = (string) $this->filter;
        }
        if (!empty($this->includes)) {
            $params['include'] = implode(',', $this->includes);
        }
        return $params;
    }
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;
        }
    }
1224124
static function parse_str($query)
    {
        if ($query === null) {
            return null;
        }

        $parts = explode('&', $query);

        $new_parts = array();
        for ($i = 0; $i < count($parts); $i++) {
            $pair = explode('=', $parts[$i]);

            if (count($pair) != 2) {
                continue;
            }

            list($key, $value) = $pair;
            $new_parts[urldecode($key)] = urldecode($value);
        }

        return $new_parts;
    }
408402
public function search()
    {
        $params = $this->getRequestParameter('params');
        $query = $params['query'];
        $class = $this->getClass($params['rootNode']);

        $rows = $this->hasRequestParameter('rows') ? (int)$this->getRequestParameter('rows') : null;
        $page = $this->hasRequestParameter('page') ? (int)$this->getRequestParameter('page') : 1;
        $startRow = is_null($rows) ? 0 : $rows * ($page - 1);

        try {
            $results = [];

            // if it is an URI
            if (strpos($query, LOCAL_NAMESPACE) === 0) {
                $resource = $this->getResource($query);
                if ($resource->exists() && $resource->isInstanceOf($class)) {
                    $results = new ResultSet([$resource->getUri()], 1);
                }
            }

            //  if there is no results based on considering the query as URI
            if (empty($results)) {
                $results = $this->getServiceLocator()->get(Search::SERVICE_ID)->query($query, $class->getUri(), $startRow, $rows);
            }

            $totalPages = is_null($rows) ? 1 : ceil( $results->getTotalCount() / $rows );

            $response = new StdClass();
            if(count($results) > 0 ){

                foreach($results as $uri) {
                    $instance = $this->getResource($uri);
                    $instanceProperties = array(
                        'id' => $instance->getUri(),
                        OntologyRdfs::RDFS_LABEL => $instance->getLabel()
                    );

                    $response->data[] = $instanceProperties;
                }
            }
    		$response->success = true;
            $response->page = empty($response->data) ? 0 : $page;
    		$response->total = $totalPages;
    		$response->records = count($results);

    		$this->returnJson($response, 200);
        } catch (SyntaxException $e) {
            $this->returnJson(array(
                'success' => false,
                'msg' => $e->getUserMessage()
            ));
        }
    }
567563
private function parse()
    {
        $opts = $this->result->options;
        $commandName = $this->result->command_name;
        $command = null;
        $optionSet = $argumentSet = false;

        // special treatment for -h --help main command options
        if ($opts['help'] === true) {
            $commandName = 'help';
        }

        if ($commandName) {
            $configFile = $this->paths['configs'] . 'commands/' . $commandName . '.yml';
            $command = new Command($configFile);
        }

        // check if any option is set
        // basically check for --version -v --help -h options
        foreach ($opts as $name => $value) {
            if ($value === true) {
                $optionSet = true;
                break;
            }
        }

        // fire up subcommand
        if (isset($command['callback'])) {
            $this->invoke($command['callback'], $command);
        }

        if ($commandName === false && $optionSet === false && $argumentSet === false) {
            $this->parser->outputter->stdout("Type 'phrozn help' for usage.\n");
        }
    }
958786
protected function parse()
    {
        try {
            $data = app(Browscap::class)->getBrowser($this->userAgent);
        } catch (Exception $e) {
            return;
        }

        foreach ($data as $key => $value) {
            // Force lowercase on key
            $key = strtolower($key);

            // Remove whitespaces from value
            $value = trim($value);

            // Switch it up!
            switch ($key) {
                case 'ismobiledevice':
                    $this->isMobile = !empty($value);
                    break;
                case 'istablet':
                    $this->isTablet = !empty($value);
                    break;
                case 'crawler':
                    $this->isCrawler = !empty($value);
                    break;
                case 'majorver':
                    $this->majorVersion = (int) $value;
                    break;
                case 'minorver':
                    $this->minorVersion = (int) $value;
                    break;
                case 'device_type':
                    $this->device = $value;
                    break;
                case 'device_pointing_method':
                    $this->devicePointer = $value;
                    break;
                case 'browser_maker':
                    $this->publisher = $value;
                    break;
                case 'comment':
                    $this->browserWithVersion = $value;
                    break;
                case 'browser':
                case 'platform':
                    $this->{$key} = $value;
                    break;
            }
        }

        // Set version and if major and minor
        // wasn't present in the data array
        // we'll set them as well
        $this->setVersion($data->version);

        // Mark parsing as successful
        $this->successful = true;
    }
949545
private function parse(&$params, &$query) {

		//Check the type of param binding ("?" = all keys are numeric or ":" = all keys are strings)
	 	if(0 !== count(array_filter(array_keys($params), 'is_string'))) {
			
			preg_match_all('#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#', $query, $variables);

			if(true === isset($variables[0])) {

				$parameters = [];

				foreach($variables[0] as $index => $variable) {
					
					if(false === array_key_exists($variables[1][$index], $params)) {
						return trigger_error(sprintf('Parameter "%s" missing from bind parameters', $variables[1][$index]), E_USER_ERROR);
					}
					
					$parameters[] =& $params[$variables[1][$index]];
					$query = str_replace($variables[0][$index], '?', $query);
				}

				$params = $parameters;
			}
	 	}

		$bind = [];

		if(count($params) > 0) {

			$types = '';

			foreach($params as $param => $value) {

				switch(gettype($value)) {
		            
		            case 'NULL'		:
		            case 'string'	: $types .= 's'; break;

		            case 'boolean'	:
		            case 'integer'	: $types .= 'i'; break;
		            
		            case 'blob'		: $types .= 'b'; break;
		            
		            case 'double'	: $types .= 'd'; break;
		        }
			}

			$bind[] =& $types;

			foreach($params as $param => $value) {
				$bind[] =& $params[$param];
			}
		}

		return $bind;
	}
755053
private function parseCptQueryVars() {
        if ( isset( $this->query_vars['post_type'] ) ) {
            $queryable = get_post_types( [ 'publicly_queryable' => TRUE ] );
            if (
                ! is_array( $this->query_vars['post_type'] )
                && ! in_array( $this->query_vars['post_type'], $queryable, TRUE )
            ) {
                unset( $this->query_vars['post_type'] );
            } elseif ( is_array( $this->query_vars['post_type'] ) ) {
                $allowed = array_intersect( $this->query_vars['post_type'], $queryable );
                $this->query_vars['post_type'] = $allowed;
            }
        }
    }
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);
            }
        }
    }