Given an HTTP query in an array (key-value pairs), decode it
into an Auth_OpenID_Request object.

@param array $query
@return Auth_OpenID_ServerError|mixed
486438
function decode($query)
    {
        if (!$query) {
            return null;
        }

        $message = Auth_OpenID_Message::fromPostArgs($query);

        if ($message === null) {
            /*
             * It's useful to have a Message attached to a
             * ProtocolError, so we override the bad ns value to build
             * a Message out of it.  Kinda kludgy, since it's made of
             * lies, but the parts that aren't lies are more useful
             * than a 'None'.
             */
            $old_ns = $query['openid.ns'];

            $query['openid.ns'] = Auth_OpenID_OPENID2_NS;
            $message = Auth_OpenID_Message::fromPostArgs($query);
            return new Auth_OpenID_ServerError(
                  $message,
                  sprintf("Invalid OpenID namespace URI: %s", $old_ns));
        }

        $mode = $message->getArg(Auth_OpenID_OPENID_NS, 'mode');
        if (!$mode) {
            return new Auth_OpenID_ServerError($message,
                                               "No mode value in message");
        }

        if (Auth_OpenID::isFailure($mode)) {
            return new Auth_OpenID_ServerError($message,
                                               $mode->message);
        }

        $handlerCls = Auth_OpenID::arrayGet($this->handlers, $mode,
                                            $this->defaultDecoder($message));

        if (!is_a($handlerCls, 'Auth_OpenID_ServerError')) {
            return call_user_func_array(array($handlerCls, 'fromMessage'),
                                        array($message, $this->server));
        } else {
            return $handlerCls;
        }
    }
1166090
public static function parseUrlQuery($query)
    {
        $result = [];
        $pairs = explode('&', $query);
        foreach ($pairs as $pair) {
            $parts = explode('=', $pair);
            $rawKey = $parts[0];
            $rawValue = isset($parts[1]) ? $parts[1] : '';
            $value = urldecode($rawValue);
            $key = strtr(urldecode($rawKey), ['[' => '.', ']' => '']);
            Arr::set($result, $key, $value);
        }
        return $result;
    }
712001
private function parseQuery($query) {
        if (is_array($query)) {
            return $query;
        }

        // "+" sign is reserved and must always be encoded,
        // otherwise it is interpreted as a space
        $queryString = str_replace('+', '%2B', $query);
        parse_str($queryString, $query);

        return $query;
    }
1189720
public function query($query=null, $params = [])
    {
        $result = false;
        $result_key = [];
        
        if ($query && static::isSql($query)) {
            $sql = $query;
        } else {
            $result_key = $this->getQuery()->set($query)->get('result_key');
            
            $queryType = $this->getQuery()->type();
            
            // limit select count
            if ((!$queryType || $queryType === 'select') 
                && !isset($this->getQuery()['count']) 
                && !isset($this->getQuery()['limit'])
                && !isset($this->getQuery()['pagesize'])) 
            {
                $this->getQuery()->set('limit', 1000);
            }
            
            // update must set where
            if (($queryType === 'update' || $queryType === 'delete') && !$this->getQuery()->get('where')) {
                Ioc::logger('db')->error('query no set where: ' . json_encode($this->getQuery()->all()));
                return false;
            }
            
            $sql = $this->parse();
        }
        
        if ($params) {
            $this->bindParams($params);
        }
        
        $this->lastSql = $this->formatSql($sql);
        
        // sql log
        Ioc::logger('db')->debug($sql);
        
        try {
            $this->getAdapter()->prepare($sql);
            if (!empty($this->binds)) {
                $this->getAdapter()->bindParams($this->binds);
            }
            $bool = $this->getAdapter()->execute();
            
            if (!$bool) {
                throw new Exception($this->getAdapter()->getErrorMessage());
            }
        } catch (Exception $e) {
            
            $this->getAdapter()->rollback();
            throw new Exception('Excute sql error: ' . $e->getMessage() . ', sql:' . $sql);
        }
        
        $rawStatement = explode(" ", $sql);
        $statement = strtolower(trim($rawStatement[0]));
        
        if ($statement === 'show') {
            $result = $this->getAdapter()->fetchAll($fetchmode);
        } elseif ($statement === 'select') {
            $rkeys = $result_key ? StringHelper::toArray($result_key, ',\s') : null;
            
            while($rs = $this->getAdapter()->fetch()) {
                // 如果指定返回结果集的key，则按key重组数据
                if ($rkeys) {
                    if (count($rkeys) == 1) {
                        $rk1 = trim($rkeys[0]);
                        if (isset($rs[$rk1])) {
                            $result[$rs[$rk1]] = $rs;
                        } else {
                            $result[] = $rs;
                        }
                    } elseif (count($rkeys) == 2) {
                        $rk1 = trim($rkeys[0]);
                        $rk2 = trim($rkeys[1]);
                        if (!empty($rk2)) {
                            $result[$rs[$rk1]][$rs[$rk2]] = $rs;
                        } else {
                            $result[$rs[$rk1]][] = $rs;
                        }
                    }
                } else {
                    $result[] = $rs;
                }
            }
        } elseif ($statement === 'update' || $statement === 'delete') {
            $result = $this->getAdapter()->numberOfRows();
        } elseif ($statement === 'insert') {
            $result = $this->getAdapter()->lastId();
        } else {
            return null;
        }
        
        return $result;
    }
259783
protected function _resolveKey($query)
    {
        if (is_string($this->_key)) {
            return $this->_key;
        }
        $func = $this->_key;
        $key = $func($query);
        if (!is_string($key)) {
            $msg = sprintf('Cache key functions must return a string. Got %s.', var_export($key, true));
            throw new RuntimeException($msg);
        }

        return $key;
    }
1000025
public function request(&$query)
    {
        global $_web_access_compress_reply;
        global $_web_access_post_xmlrpc;
        global $_web_access_retry_timeout;
        global $_web_access_retry_timeout_max;

        $query['State'] = 'BAD';
        $query['HDatas'] = '';
        $query['Datas'] = '';
        $query['DatasSize'] = 0;
        $query['DatasSent'] = 0;
        $query['Response'] = '';
        $query['ResponseSize'] = 0;
        $query['Headers'] = array();
        $query['Close'] = false;
        $query['Times'] = array(
            'open' => array(-1.0, -1.0),
            'send' => array(-1.0, -1.0),
            'receive' => array(-1.0, -1.0, 0),
        );


        // if async, in error, and maximal timeout, then forget the request and return false.
        if (($query['Callback'] != null) && ($this->_state == 'BAD')) {
            if ($this->_bad_timeout > $_web_access_retry_timeout_max) {
                $this->console->writeln($this->_webaccess_str.'$f00Request refused for consecutive errors $555('.$this->_bad_timeout
                    ." / ".$_web_access_retry_timeout_max.")");

                return false;
            } else {
                // if not max then accept the request
                // and try a request (minimum $_web_access_retry_timeout/2 after previous try)
                $time = time();
                $timeout = ($this->_bad_timeout / 2) - ($time - $this->_bad_time);
                if ($timeout < 0) {
                    $timeout = 0;
                }
                $this->_bad_time = $time - $this->_bad_timeout + $timeout;
            }
        }

        // build datas to send
        if (($query['Callback'] == null) || (is_array($query['Callback']) &&
                isset($query['Callback'][0]) &&
                is_callable($query['Callback'][0]))
        ) {

            if (is_string($query['QueryDatas']) && strlen($query['QueryDatas']) > 0) {
                $msg = "POST ".$query['Path']." HTTP/1.1\r\n";
                $msg .= "Host: ".$this->_host."\r\n";
                $msg .= "User-Agent: ".$this->_agent."\r\n";
                $msg .= "Cache-Control: no-cache\r\n";

                if ($_web_access_compress_reply) {
                    // ask compression of response if gzdecode() and/or gzinflate() is available
                    if (function_exists('gzdecode') && function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate, gzip\r\n";
                    } elseif (function_exists('gzdecode')) {
                        $msg .= "Accept-Encoding: gzip\r\n";
                    } elseif (function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate\r\n";
                    }
                }

                // echo "\nData:\n\n".$query['QueryDatas']."\n";  // for debug purposes, don't remove!

                if ($query['IsXmlrpc'] === true) {
                    if ($_web_access_post_xmlrpc) {
                        $msg .= "Content-type: application/x-www-form-urlencoded; charset=UTF-8\r\n";

                        echo "\n=========================== Data =================================\n\n".$query['Datas']."\n";

                        $query['QueryDatas'] = "xmlrpc=".urlsafe_base64_encode($query['QueryDatas']);
                    } else {
                        $msg .= "Content-type: text/xml; charset=UTF-8\r\n";
                    }

                    if ($this->_compress_request == 'gzip' && function_exists('gzencode')) {
                        $msg .= "Content-Encoding: gzip\r\n";
                        $query['QueryDatas'] = gzencode($query['QueryDatas']);
                    } elseif ($this->_compress_request == 'deflate' && function_exists('gzdeflate')) {
                        $msg .= "Content-Encoding: deflate\r\n";
                        $query['QueryDatas'] = gzdeflate($query['QueryDatas']);
                    }
                } elseif (is_string($query['IsXmlrpc'])) {
                    $msg .= "Content-type: ".$query['IsXmlrpc']."\r\n";
                    $msg .= "Accept: */*\r\n";
                } else {
                    $msg .= "Content-type: ".$query['MimeType']."\r\n";
                    $msg .= "Accept: */*\r\n";
                }

                $msg .= "Content-length: ".strlen($query['QueryDatas'])."\r\n";

                $query['HDatas'] = $msg;

                $query['State'] = 'OPEN';
                $query['Retries'] = 0;

                // print_r($msg); for debugging purposes - don't remove

                // add the query in spool
                $this->_spool[] = &$query;

                if ($query['Callback'] == null) {
                    $this->_wait = true;
                    $this->_open($query['OpenTimeout'], $query['WaitTimeout']); // wait more in not callback mode
                    $this->_spool = array();
                    $this->_wait = false;

                    return $query['Response'];
                } else {
                    $this->_open();
                }
            } else {
                $msg = "GET ".$query['Path']." HTTP/1.1\r\n";
                $msg .= "Host: ".$this->_host."\r\n";
                $msg .= "User-Agent: ".$this->_agent."\r\n";
                $msg .= "Cache-Control: no-cache\r\n";
                if ($_web_access_compress_reply) {
                    // ask compression of response if gzdecode() and/or gzinflate() is available
                    if (function_exists('gzdecode') && function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate, gzip\r\n";
                    } elseif (function_exists('gzdecode')) {
                        $msg .= "Accept-Encoding: gzip\r\n";
                    } elseif (function_exists('gzinflate')) {
                        $msg .= "Accept-Encoding: deflate\r\n";
                    }
                }
                $msg .= "Content-type: ".$query['MimeType']."; charset=UTF-8\r\n";
                $msg .= "Content-length: ".strlen($query['QueryDatas'])."\r\n";
                $query['HDatas'] = $msg;

                $query['State'] = 'OPEN';
                $query['Retries'] = 0;

                // add the query in spool
                $this->_spool[] = &$query;

                if ($query['Callback'] == null) {
                    $this->_wait = true;
                    $this->_open($query['OpenTimeout'], $query['WaitTimeout']); // wait more in not callback mode
                    $this->_spool = array();
                    $this->_wait = false;

                    return $query['Response'];
                } else {
                    $this->_open();
                }
            }

        } else {

            $this->console->writeln($this->_webaccess_str.'Bad callback function:$fff '.$query['Callback']);

            return false;
        }

        return true;
    }
1312270
public function query($query, $params = array())
  {
    $curl = new Curl();
    $params['key'] = $this->server_key;
    $result = json_decode($curl->call(self::GOOGLEPLUS_API_URL . trim($query, '/') . '?' . http_build_query($params), array(), 'GET', true), true);
    if(!isset($result['error'])) {
      return $result;
    }
    return $this->debug_mode ? $result['error']['message'] : null;
  }
1225204
public static function parse($query)
    {
        if (!is_string($query)) {
            throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                'Could not parse query string: expected a non-empty string, %s given',
                is_object($query) ? get_class($query) : gettype($query)
            ));
        }

        $queryWithoutSeparator = ltrim($query, '?');

        if (strlen($queryWithoutSeparator) <= strlen('SAMLRequest=')) {
            throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                'Could not parse query string: expected a non-empty string of at least %d characters, got "%s"',
                strlen('SAMLRequest='),
                $queryWithoutSeparator
            ));
        }

        $queryParameters = explode('&', $queryWithoutSeparator);

        $parameters = [];
        foreach ($queryParameters as $queryParameter) {
            if (!(strpos($queryParameter, '=') > 0)) {
                throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                    'Could not parse "%s": it does not contain a valid key-value pair',
                    $queryParameter
                ));
            }

            list($key, $value) = explode('=', $queryParameter, 2);

            if (!in_array($key, self::$samlParameters)) {
                continue;
            }

            if (array_key_exists($key, $parameters)) {
                throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                    'Invalid ReceivedAuthnRequest query string ("%s"): parameter "%s" already present',
                    $queryWithoutSeparator,
                    $key
                ));
            }

            $parameters[$key] = $value;
        }

        if (!isset($parameters[self::PARAMETER_REQUEST])) {
            throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                'Invalid ReceivedAuthnRequest query string ("%s"): parameter "%s" not found',
                $queryWithoutSeparator,
                self::PARAMETER_REQUEST
            ));
        }

        if (base64_decode(urldecode($parameters[self::PARAMETER_REQUEST]), true) === false) {
            throw new InvalidRequestException('Failed decoding SAML request, did not receive a valid base64 string');
        }

        $parsedQueryString = new self($parameters[self::PARAMETER_REQUEST]);

        if (isset($parameters[self::PARAMETER_RELAY_STATE])) {
            $parsedQueryString->relayState = $parameters[self::PARAMETER_RELAY_STATE];
        }

        if (isset($parameters[self::PARAMETER_SIGNATURE])) {
            if (!isset($parameters[self::PARAMETER_SIGNATURE_ALGORITHM])) {
                throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                    'Invalid ReceivedAuthnRequest query string ("%s") contains a signature but not a signature algorithm',
                    $queryWithoutSeparator
                ));
            }

            if (base64_decode(urldecode($parameters[self::PARAMETER_SIGNATURE]), true) === false) {
                throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                    'Invalid ReceivedAuthnRequest query string ("%s"): signature is not base64 encoded correctly',
                    $queryWithoutSeparator
                ));
            }

            $parsedQueryString->signature = $parameters[self::PARAMETER_SIGNATURE];
            $parsedQueryString->signatureAlgorithm = $parameters[self::PARAMETER_SIGNATURE_ALGORITHM];
            return $parsedQueryString;
        }

        if (isset($parameters[self::PARAMETER_SIGNATURE_ALGORITHM])) {
            throw new InvalidReceivedAuthnRequestQueryStringException(sprintf(
                'Invalid ReceivedAuthnRequest query string ("%s") contains a signature algorithm but not a signature',
                $queryWithoutSeparator
            ));
        }

        return $parsedQueryString;
    }
1331985
protected static function parseQuery($query)
    {
        if (is_array($query))
            return $query;

        if (empty($query))
            return null;

        if (!is_string($query))
            throw new \InvalidArgumentException('Query must be associative array or string');
        
        $query = ltrim($query, '?');
        $query = str_replace('&amp;', '&', $query);
        $parts = explode('&', $query);
        $values = [];
        foreach ($parts as $part)
        {
            $subparts = explode('=', $part, 2);
            if (count($subparts) === 1)
                $values[$part] = '1';
            else
                $values[$subparts[0]] = $subparts[1];
        }

        return empty($values) ? null : $values;
    }
652589
public static function find(array $query)
    {
        $employees = Client::get("employee", $query);
        return array_map(function ($data) { return new self($data); }, $employees);
    }
691964
private function parseHttpQuery($query)
    {
        /* can't use parse_str, because the minimum supported PHP version
         * is 5.3, which still has the magic_quotes_gpc option that affects its
         * result, so some users could hypothetically have that enabled */
        if (empty($query)) {
            return array();
        }

        $result = array();
        $parts = explode('&', $query);
        foreach ($parts as $p) {
            $keyval = explode('=', $p);
            $result[urldecode($keyval[0])] = urldecode($keyval[1]);
        }
        return $result;
    }
949283
protected function filterNonSearchableParameters(array $query) {
        $nonSearchableParameterNames = [$this->getQueryModeParameterName()];

        if (property_exists($this, 'withParameterName')) {
            $nonSearchableParameterNames[] = $this->withParameterName;
        }

        if (property_exists($this, 'sortParameterName')) {
            $nonSearchableParameterNames[] = $this->sortParameterName;
        }

        return array_except($query, $nonSearchableParameterNames);
    }
221723
public function withQueryParams(array $query)
    {
        $params = $this->getQueryParams();

        foreach ($query as $key => $value) {
            $params[$key] = $value;
        }

        $this->queryParams = $params;
    }
207602
private static function encodeQueryParts($query)
    {
        $queryParts = explode('&', $query);
        $queryArray = [];

        foreach ($queryParts as $queryPart) {
            $pieces = explode('=', $queryPart, 2);

            $key = rawurlencode($pieces[0]);
            $value = rawurlencode($pieces[1]);

            $queryArray[$key][] = $value;
        }
        return $queryArray;
    }
1323151
private function _query($query)
    {
        if ($this->encrypted) {
            return OneLogin_Saml2_Utils::query($this->decryptedDocument, $query);
        } else {
            return OneLogin_Saml2_Utils::query($this->document, $query);
        }
    }
166341
public function prepare(array $query): array
	{
		if (isset($query['WHERE']) && sizeof($query['WHERE']) > 1) {
			$where = $query['WHERE'];

			$query['WHERE'] = [[
				'expr_type' => 'bracket_expression',
				'base_expr' => '',
				'sub_tree' => $where,
			]];

			foreach ($where as $where_data) {
				$query['WHERE'][0]['base_expr'] .= ' ' . $where_data['base_expr'];
			}

			$query['WHERE'][0]['base_expr'] = '(' . trim($query['WHERE'][0]['base_expr']) . ')';
		}

		return $query;
	}
259382
public function makeRequest(string $type = null, array $query = [])
    {
        if ($type) {
            $query[$type] = null;
        }

        $query['key'] = $this->apiKey;

        return $this->decodeResponse($this->client
            ->get($this->baseUrl, compact('query'))
            ->getBody()
            ->getContents());
    }