Create a new request using PHP super global variables.

@param array $query
@param array $post
@param array $cookie
@param array $server
@param array $files
@param array $env
@param null  $content

@return static
348771
public static function createFromGlobals(
        array $query = null,
        array $post = null,
        array $cookie = null,
        array $server = null,
        array $files = null,
        array $env = null,
        $content = null
    ) {
        $query = isset($query) ? $query : $_GET;
        $post = isset($post) ? $post : $_POST;
        $cookie = isset($cookie) ? $cookie : $_COOKIE;
        $server = isset($server) ? $server : $_SERVER;
        $files = isset($files) ? $files : $_FILES;
        $env = isset($env) ? $env : $_ENV;

        $server = self::setServerParam($server, [
            'CONTENT_LENGTH' => 'HTTP_CONTENT_LENGTH',
            'CONTENT_TYPE'   => 'HTTP_CONTENT_TYPE',
        ]);

        return new static($query, $post, $cookie, $server, $files, $env, $content);
    }
1313633
public function search($query, array $filters = [], $path = '/search.json')
	{
		$filters['q'] = $query;
		$url = $this->getUrl() . $path . '?' . http_build_query($filters);

		$this->_response = new Response(['json' => $this->request($url)]);
		return $this;
	}
1133094
def create_request_with_query(self, kind, query, size="thumb", fmt="json"):
        
        if kind == "data" or kind == "files":
            url = "{}/{}.{}".format(base_url, kind, fmt)
        elif kind == "images":
            url = "{}/images/{}.{}".format(base_url, size, fmt)
        self.url = url
        self.r = requests.get(url, params=unquote(urlencode(query)))
789099
public function constructQuery($source, $query, $aggs, $post_query, $settings) {
        $query_data = [
            'ignore_unavailable' => true,
        ];
        $query_body = [
            'size' => 100,
        ];
        $meta = [
            'aggs' => [],
            'flatten' => true,
            'map' => [],
            'scroll' => false,
            'post_query' => false,
            'count' => false,
        ];

        $from = Util::get($settings, 'from', time());
        $to = Util::get($settings, 'to', time());
        $date_field = Util::get($settings, 'date_field');

        // Construct filter query clauses.
        $filter_data = $this->constructFilter($source, $query, $date_field, $from, $to);
        if(!is_null($filter_data)) {
            $query_body['query'] = [
                'bool' => [
                    'filter' => $filter_data
                ]
            ];
        }

        // Set index.
        if(Util::exists($settings, 'index')) {
            $query_data['index'] = $settings['index'];

            if(Util::get($settings, 'date_based', false)) {
                $query_data['index'] = implode(',', Util::generateDateIndices($query_data['index'], Util::get($settings, 'date_interval'), $from, $to));
            }
        }

        // Construct agg queries clauses.
        $agg_data = $this->constructAggs($aggs);

        // Construct setting data.
        if(!is_null($agg_data)) {
            $query_body['aggs'] = $agg_data;
            // When executing an agg, we don't care about the actual hits.
            $query_body['size'] = 0;
            $meta['aggs'] = $aggs;
        }
        if(array_key_exists('count', $settings)) {
            $meta['count'] = (bool) $settings['count'];

            // Same thing if we want a count and have no aggs or post query.
            if(is_null($post_query)) {
                $query_body['size'] = 0;
            }
        }
        if(array_key_exists('flatten', $settings)) {
            $meta['flatten'] = (bool) $settings['flatten'];
        }
        if(array_key_exists('map', $settings)) {
            $meta['map'] = (array) $settings['map'];
        }
        if(!is_null($post_query)) {
            $meta['post_query'] = true;
        }
        // Determine whether to use a scroll query, which is more efficient.
        /*
        if(...) {
            $meta['scroll'] = true;
        }
         */

        // Construct setting clauses.
        $query_body = array_merge($query_body, $this->constructSettings($settings));

        $query_data['body'] = $query_body;

        return [$query_data, $meta];
    }
627560
public static function newInstanceFromWordPressQuery(\WP_Query $query)
    {
        $newQuery = new static;

        foreach (get_object_vars($query) as $property => $value)
        {
            $newQuery->$property = $value;
        }

        return $newQuery;
    }
947019
public function sendSparqlUpdateQuery($url, $query)
    {
        // because you can't just fire multiple requests with the same CURL class instance
        // we have to be creative and re-create the class everytime a request is to be send.
        // FYI: https://github.com/php-curl-class/php-curl-class/issues/326
        $class = get_class($this->httpClient);
        $phpVersionToOld = version_compare(phpversion(), '5.5.11', '<=');
        // only reinstance the class if its not mocked
        if ($phpVersionToOld && false === strpos($class, 'Mockery')) {
            $this->httpClient = new $class;
        }

        // TODO extend Accept headers to further formats
        $this->httpClient->setHeader('Accept', 'application/sparql-results+json');
        $this->httpClient->setHeader('Content-Type', 'application/sparql-update');

        return $this->httpClient->get($url, array('query' => $query));
    }
1118797
public function post($uri, $query)
    {
        $this->client->post($uri, $query);

        return $this->createResponse();
    }
367035
public function buildRequestParts(
        string $url,
        array $query = [],
        array $body = [],
        array $server = []
    ): RequestParts {
        $url = trim($url, '/');
        $url = trim("{$this->version}/$url", '/');
        $url = $this->buildUrlParams($url, $query);

        return new RequestParts(
            $url,
            [
                'json' => $body,
                'headers' => $server,
            ],
            [
                'decode_content' => 'gzip',
            ]
        );
    }
1273412
public static function createFromGlobals(array $globals = null) : Request
    {
        $globals = $globals === null
                ? Uri::fixSchemeProxyFromGlobals($_SERVER)
                : $globals;

        $method        = isset($globals['REQUEST_METHOD']) ? $globals['REQUEST_METHOD'] : null;
        $method        = $method ? strtoupper($method) : $method;
        $uri           = Uri::createFromGlobals($globals);
        $body          = new RequestBody();
        $uploadedFiles = UploadedFile::createFromGlobals($globals);
        $headers       = static::parseForHeadersFromGlobal($globals);
        $request       = new static($method, $uri, $headers, $globals, [], $body, $uploadedFiles);
        $cookies       = Cookies::parseHeader($request->getHeader('Cookie'));

        /**
         * @var Request $request
         */
        $request = $request->withCookieParams($cookies);
        if ($method === 'POST' && in_array(
            $request->getMediaType(),
            ['application/x-www-form-urlencoded', 'multipart/form-data']
        )) {
            // parsed body must be $_POST
            $request = $request->withParsedBody($_POST);
        }

        return $request;
    }
311748
public static function fromString($query, array $data = [])
    {
        $url = parse_url($query);
        $query = isset($url['query']) ? $url['query'] : $url['path'];
        parse_str($query, $data);

        return new QueryString($data);
    }
76661
public function put(string $path, array $query = [], array $body = []): ResponseInterface
    {
        return $this->request('PUT', $path, $query, $body);
    }
468721
public function fileServe($query, $callback=null)
    {
        if (!array_key_exists('REQUEST_URI', $_SERVER)) return $query;
        $path_prefix = $this->getPathPrefix();

        if (!preg_match("/$path_prefix\/assets\/(.*)$/i",
         $_SERVER['REQUEST_URI'])) return $query;
            
        $file_path = self::getAssetPath();

        if (!$file_path) return $query;
        
        // check if this file is whitelisted
        if (!$this->shouldLoadFile($this->getAssetFileName())) return $query;

        $content_type = self::getContentType($file_path);
        header('Content-type: ' . $content_type);
        header('Content-Length: ' . filesize($file_path));
        http_response_code(200);
        readfile($file_path);
        if ($callback) {
            $callback();
        }
        exit;
        return $query;
    }
217331
public static function create($method, $path, array $env = array())
    {
        $request = new self($method, $path);

        if (function_exists('getallheaders')) {
            $request->headers = getallheaders();
        } else {
            // TODO: filter array keys by their prefix, consider adding an extension function for this.
            $request->headers = self::createHeadersFromServerGlobal($env);
        }

        if (isset($env['_SERVER'])) {
            $request->serverParameters = $env['_SERVER'];
        } else {
            $request->serverParameters = $env;
        }
        $request->parameters = isset($env['_REQUEST']) ? $env['_REQUEST'] : array();
        $request->queryParameters = isset($env['_GET']) ? $env['_GET'] : array();
        $request->bodyParameters = isset($env['_POST']) ? $env['_POST'] : array();
        $request->cookieParameters = isset($env['_COOKIE']) ? $env['_COOKIE'] : array();
        $request->sessionParameters = isset($env['_SESSION']) ? $env['_SESSION'] : array();

        return $request;
    }
198699
function get($path, $query = null, $headers = null, $curlOpts = null) {
        $payload = $this -> encodePostBody($query);
        
        if ($payload !== "") {
            if (strpos($path, '?')) {
                $url = $path . "&" . $payload;
            } else {
                $url = $path . "?" . $payload;
            }
        }else{
            $url = $path;
        }
        
        return $this -> request($url, self::HTTP_GET, '', $headers, $curlOpts);
    }
1347355
function query( $request, $content = '', $doSpeedCheck = 0 )
    {
        $this->error = $this->warn = array();
        $this->result_status_code = NULL;

        // is our request a http(s):// ... ?
        if (preg_match('/^(http|https):\/\//i',$request))
        {
            $location = parse_url($request);
            $this->connect($location['host'],$location['port']);
            $this->set_login($location['user'],$location['pass']);

            $request = $location['path'];
            $content = $location['query'];

            if ( strlen($request) < 1 )
            {
                $request = '/';
            }

        }

        $array_headers = array(
            'User-Agent' => "HTTPSocket/$this->version",
            'Host' => ( $this->remote_port == 80 ? parse_url($this->remote_host,PHP_URL_HOST) : parse_url($this->remote_host,PHP_URL_HOST).":".$this->remote_port ),
            'Accept' => '*/*',
            'Connection' => 'Close' );

        foreach ( $this->extra_headers as $key => $value )
        {
            $array_headers[$key] = $value;
        }

        $this->result = $this->result_header = $this->result_body = '';

        // was content sent as an array? if so, turn it into a string
        if (is_array($content))
        {
            $pairs = array();

            foreach ( $content as $key => $value )
            {
                $pairs[] = "$key=".urlencode($value);
            }

            $content = join('&',$pairs);
            unset($pairs);
        }

        $OK = TRUE;

        // instance connection
        if ($this->bind_host)
        {
            $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            socket_bind($socket,$this->bind_host);

            if (!@socket_connect($socket,$this->remote_host,$this->remote_port))
            {
                $OK = FALSE;
            }

        }
        else
        {
            $socket = @fsockopen( $this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 10 );
        }

        if ( !$socket || !$OK )
        {
            $this->error[] = "Can't create socket connection to $this->remote_host:$this->remote_port.";
            return 0;
        }

        // if we have a username and password, add the header
        if ( isset($this->remote_uname) && isset($this->remote_passwd) )
        {
            $array_headers['Authorization'] = 'Basic '.base64_encode("$this->remote_uname:$this->remote_passwd");
        }

        // for DA skins: if $this->remote_passwd is NULL, try to use the login key system
        if ( isset($this->remote_uname) && $this->remote_passwd == NULL )
        {
            $array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}";
        }

        // if method is POST, add content length & type headers
        if ( $this->method == 'POST' )
        {
            $array_headers['Content-type'] = 'application/x-www-form-urlencoded';
            $array_headers['Content-length'] = strlen($content);
        }
        // else method is GET or HEAD. we don't support anything else right now.
        else
        {
            if ($content)
            {
                $request .= "?$content";
            }
        }

        // prepare query
        $query = "$this->method $request HTTP/1.0\r\n";
        foreach ( $array_headers as $key => $value )
        {
            $query .= "$key: $value\r\n";
        }
        $query .= "\r\n";

        // if POST we need to append our content
        if ( $this->method == 'POST' && $content )
        {
            $query .= "$content\r\n\r\n";
        }

        // query connection
        if ($this->bind_host)
        {
            socket_write($socket,$query);

            // now load results
            while ( $out = socket_read($socket,2048) )
            {
                $this->result .= $out;
            }
        }
        else
        {
            fwrite( $socket, $query, strlen($query) );

            // now load results
            $this->lastTransferSpeed = 0;
            $status = socket_get_status($socket);
            $startTime = time();
            $length = 0;
            while ( !feof($socket) && !$status['timed_out'] )
            {
                $chunk = fgets($socket,1024);
                $length += strlen($chunk);
                $this->result .= $chunk;

                $elapsedTime = time() - $startTime;

                if ( $elapsedTime > 0 )
                {
                    $this->lastTransferSpeed = ($length/1024)/$elapsedTime;
                }

                if ( $doSpeedCheck > 0 && $elapsedTime > 5 && $this->lastTransferSpeed < $doSpeedCheck )
                {
                    $this->warn[] = "kB/s for last 5 seconds is below 50 kB/s (~".( ($length/1024)/$elapsedTime )."), dropping connection...";
                    $this->result_status_code = 503;
                    break;
                }

            }

            if ( $this->lastTransferSpeed == 0 )
            {
                $this->lastTransferSpeed = $length/1024;
            }

        }

        list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2);

        if ($this->bind_host)
        {
            socket_close($socket);
        }
        else
        {
            fclose($socket);
        }

        $this->query_cache[] = $query;


        $headers = $this->fetch_header();

        // what return status did we get?
        if (!$this->result_status_code)
        {
            preg_match("#HTTP/1\.. (\d+)#",$headers[0],$matches);
            $this->result_status_code = $matches[1];
        }

        // did we get the full file?
        if ( !empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body) )
        {
            $this->result_status_code = 206;
        }

        // now, if we're being passed a location header, should we follow it?
        if ($this->doFollowLocationHeader)
        {
            if ($headers['location'])
            {
                $this->redirectURL = $headers['location'];
                $this->query($headers['location']);
            }
        }
    }
646090
public function setQuery(array $query) : Request
    {
        $this->queryString = http_build_query($query);

        // Ensure that we get a value for getQuery() that's consistent with the query string, and whose scalar values
        // have all been converted to strings, to get a result similar to what we'd get with an incoming HTTP request.
        parse_str($this->queryString, $this->query);

        $this->requestUri = $this->path;

        if ($this->queryString !== '') {
            $this->requestUri .= '?' . $this->queryString;
        }

        return $this;
    }
231565
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
    {
        $this->currentUri = $this->prepareUrlForRequest($uri);

        $symfonyRequest = SymfonyRequest::create(
            $this->currentUri, $method, $parameters,
            $cookies, $files, $server, $content
        );

        $response = $this->app->prepareResponse(
            $this->app->handle(Request::createFromBase($symfonyRequest))
        );
        $this->response = $this->createTestResponse($response);

        return $this->response;
    }