This static method will create a new Request object, based on a PHP
$_SERVER array.

REQUEST_URI and REQUEST_METHOD are required.
493150
public static function createFromServerArray(array $serverArray): Request
    {
        $headers = [];
        $method = null;
        $url = null;
        $httpVersion = '1.1';

        $protocol = 'http';
        $hostName = 'localhost';

        foreach ($serverArray as $key => $value) {
            switch ($key) {
                case 'SERVER_PROTOCOL':
                    if ('HTTP/1.0' === $value) {
                        $httpVersion = '1.0';
                    } elseif ('HTTP/2.0' === $value) {
                        $httpVersion = '2.0';
                    }
                    break;
                case 'REQUEST_METHOD':
                    $method = $value;
                    break;
                case 'REQUEST_URI':
                    $url = $value;
                    break;

                // These sometimes show up without a HTTP_ prefix
                case 'CONTENT_TYPE':
                    $headers['Content-Type'] = $value;
                    break;
                case 'CONTENT_LENGTH':
                    $headers['Content-Length'] = $value;
                    break;

                // mod_php on apache will put credentials in these variables.
                // (fast)cgi does not usually do this, however.
                case 'PHP_AUTH_USER':
                    if (isset($serverArray['PHP_AUTH_PW'])) {
                        $headers['Authorization'] = 'Basic '.base64_encode($value.':'.$serverArray['PHP_AUTH_PW']);
                    }
                    break;

                // Similarly, mod_php may also screw around with digest auth.
                case 'PHP_AUTH_DIGEST':
                    $headers['Authorization'] = 'Digest '.$value;
                    break;

                // Apache may prefix the HTTP_AUTHORIZATION header with
                // REDIRECT_, if mod_rewrite was used.
                case 'REDIRECT_HTTP_AUTHORIZATION':
                    $headers['Authorization'] = $value;
                    break;

                case 'HTTP_HOST':
                    $hostName = $value;
                    $headers['Host'] = $value;
                    break;

                case 'HTTPS':
                    if (!empty($value) && 'off' !== $value) {
                        $protocol = 'https';
                    }
                    break;

                default:
                    if ('HTTP_' === substr($key, 0, 5)) {
                        // It's a HTTP header

                        // Normalizing it to be prettier
                        $header = strtolower(substr($key, 5));

                        // Transforming dashes into spaces, and uppercasing
                        // every first letter.
                        $header = ucwords(str_replace('_', ' ', $header));

                        // Turning spaces into dashes.
                        $header = str_replace(' ', '-', $header);
                        $headers[$header] = $value;
                    }
                    break;
            }
        }

        if (null === $url) {
            throw new InvalidArgumentException('The _SERVER array must have a REQUEST_URI key');
        }

        if (null === $method) {
            throw new InvalidArgumentException('The _SERVER array must have a REQUEST_METHOD key');
        }
        $r = new Request($method, $url, $headers);
        $r->setHttpVersion($httpVersion);
        $r->setRawServerData($serverArray);
        $r->setAbsoluteUrl($protocol.'://'.$hostName.$url);

        return $r;
    }
316000
public static function Request($NewRequest = NULL) {
      $Request = self::$_Request; //self::Factory(self::AliasRequest);
      if (!is_null($NewRequest)) {
			if (is_string($NewRequest))
				$Request->WithURI($NewRequest);
			elseif (is_object($NewRequest))
				$Request->FromImport($NewRequest);
		}
      
      return $Request;
   }
454360
public static function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
    {
        return self::getServerRequestFactory()->createServerRequest($method, $uri, $serverParams);
    }
1103881
public function createServerRequestFromArray(array $server){
        $method     = $server["REQUEST_METHOD"] ?? "GET";

        return new ServerRequest(
            $method,
            (new UriFactory())->createFromServer($server),
            $server,
            self::getUploadedFiles($_FILES),
            $_COOKIE,
            $_GET,
            self::getProtocolVersion($server)
        );
    }
176366
def create(cls, data=None, api_key=None, endpoint=None, add_headers=None,
               **kwargs):
        """"""
        cls.validate(data)
        inst = cls(api_key=api_key)
        endpoint = ''
        return inst.request('POST',
                            endpoint=endpoint,
                            data=data,
                            query_params=kwargs,
                            add_headers=add_headers,
                            )
858484
protected static function setupRequestMethod()
    {
        switch ($_SERVER['REQUEST_METHOD']) {
            case 'GET':
                self::$requestMethod = &$_GET;
                break;
            case 'POST':
                self::$requestMethod = &$_POST;
                break;
            default:
        }
        return self::$requestMethod;
    }
1327785
public static function from_request($http_method = null, $http_url = null, $parameters = null) {
        $scheme = (!is_https()) ? 'http' : 'https';
        $port = "";
        if ($_SERVER['SERVER_PORT'] != "80" && $_SERVER['SERVER_PORT'] != "443" && strpos(':', $_SERVER['HTTP_HOST']) < 0) {
            $port = ':' . $_SERVER['SERVER_PORT'];
        }
        @$http_url or $http_url = $scheme .
        '://' . $_SERVER['HTTP_HOST'] .
        $port .
        $_SERVER['REQUEST_URI'];
        @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];

        // We weren't handed any parameters, so let's find the ones relevant to
        // this request.
        // If you run XML-RPC or similar you should use this to provide your own
        // parsed parameter-list
        if (!$parameters) {
            // Find request headers
            $request_headers = OAuthUtil::get_headers();

            // Parse the query-string to find GET parameters
            $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);

            $ourpost = $_POST;
            // Add POST Parameters if they exist
            $parameters = array_merge($parameters, $ourpost);

            // We have a Authorization-header with OAuth data. Parse the header
            // and add those overriding any duplicates from GET or POST
            if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
                $header_parameters = OAuthUtil::split_header($request_headers['Authorization']);
                $parameters = array_merge($parameters, $header_parameters);
            }

        }

        return new OAuthRequest($http_method, $http_url, $parameters);
    }
424353
public static function initialize()
    {
        switch($_SERVER['REQUEST_METHOD']) {
            case "POST":
                self::$_method = self::POST;
                break;
            case "GET":
                self::$_method = self::GET;
                break;
            case "PUT":
                self::$_method = self::PUT;
                break;
            case "DELETE":
                self::$_method = self::DELETE;
                break;
            default:
                self::$_method = self::HEAD;
        }
        self::$_data = array();
        self::_parseData($_GET);
        self::_parseData($_POST);
        
        if(
            isset($_SERVER['HTTPS']) &&
            $_SERVER['HTTPS'] !== null &&
            $_SERVER['HTTPS'] !== "off"
        ) {
            self::$_https = true;
        } else {
            self::$_https = false;
        }
        
        self::$_domain = (string) $_SERVER['HTTP_HOST'];
        self::$_file = (string) $_SERVER['SCRIPT_FILENAME'];
        if(isset($_SERVER['PATH_INFO'])) {
            self::$_pathInfo = (string) $_SERVER['PATH_INFO'];
        } else {
            self::$_pathInfo = "";
        }
    }
200303
public static function create(
        $url,
        $method = RequestMethods::GET,
        array $parameters = [],
        array $cookies = [],
        array $server = [],
        array $files = [],
        array $env = [],
        $rawBody = null
    ) {
        // Define some basic server vars, but override them with the input on collision
        $server = array_replace([
                'HTTP_ACCEPT'          => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                'HTTP_HOST'            => 'localhost',
                'REMOTE_ADDR'          => '127.0.01',
                'SCRIPT_FILENAME'      => '',
                'SCRIPT_NAME'          => '',
                'SERVER_NAME'          => 'localhost',
                'SERVER_PORT'          => 80,
                'SERVER_PROTOCOL'      => 'HTTP/1.1',
                'HTTP_USER_AGENT'      => 'Cygnite/3.x',
                'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
                'HTTP_ACCEPT_CHARSET'  => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                'REQUEST_TIME'         => time(),
            ], $server);

        $query = [];
        $post = [];

        // Set the content type for unsupported HTTP methods
        switch (strtoupper($method)) {
            case RequestMethods::GET:
                $query = $parameters;
                break;
            case RequestMethods::PATCH:
            case RequestMethods::PUT:
            case RequestMethods::DELETE:
                if (!isset($server['CONTENT_TYPE'])) {
                    $server['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
                }
            // no break
            case RequestMethods::POST:
                $post = $parameters;
                break;
        }

        $server['REQUEST_METHOD'] = strtoupper($method);
        $urlParts = parse_url($url);

        $server = static::setServerData($urlParts, [
            'host' => 'HTTP_HOST',
            'path' => 'REQUEST_URI',
            'user' => 'PHP_AUTH_USER',
            'pass' => 'PHP_AUTH_PW',
        ], $server);

        if (isset($urlParts['scheme'])) {
            if ($urlParts['scheme'] == 'https') {
                $server['HTTPS'] = 'on';
                $server['SERVER_PORT'] = 443;
            } else {
                unset($server['HTTPS']);
                $server['SERVER_PORT'] = 80;
            }
        }

        if (isset($urlParts['query'])) {
            parse_str(html_entity_decode($urlParts['query']), $queryFromUrl);
            $query = array_replace($queryFromUrl, $query);
        }

        if (!isset($urlParts['path'])) {
            $urlParts['path'] = '/';
        }

        $qs = http_build_query($query, '', '&');
        $server['QUERY_STRING'] = $qs;
        $server['REQUEST_URI'] = $urlParts['path'].(count($query) > 0 ? '?'.$qs : '');

        if (isset($urlParts['port'])) {
            $server = static::setServerData($urlParts, [
                'port'                 => 'SERVER_PORT',
                ":{$urlParts['port']}" => 'HTTP_HOST',
            ], $server);
        }

        return new static($query, $post, $cookies, $server, $files, $env, $rawBody);
    }
263202
private function setRequestURI()
    {

        if (!isset($_SERVER['REQUEST_URI']) || !isset($_SERVER['SCRIPT_NAME']))
        {
            $this->request_uri = '';
        }
        else
        {

            $uri = $_SERVER['REQUEST_URI'];
            $script = $_SERVER['SCRIPT_NAME'];

            if (strpos($uri, $script) === 0)
            {
                $uri = substr($uri, strlen($script));
            }
            elseif (strpos($uri, dirname($script)) === 0)
            {
                $uri = substr($uri, strlen(dirname($script)));
            }

            if (strncmp($uri, '?/', 2) === 0)
            {
                $uri = substr($uri, 2);
            }

            $parts = preg_split('#\?#i', $uri, 2);
            $uri = $parts[0];

            if ($uri == '/' || empty($uri))
            {
                $this->request_uri = '';
            }

            $uri = parse_url($uri, PHP_URL_PATH);
            $this->request_uri = str_replace(array('//', '../'), '/', trim($uri, '/'));
        }
    }
464585
protected function createRequest($method, $url, $requestHeaders, $requestPayload, $protocolVersion)
    {
        $request = new Request(
            $method,
            $url,
            $requestHeaders,
            $requestPayload,
            $protocolVersion
        );

        return $request;
    }
51444
static function build($required=null, $optional=null,
                   $policy_url=null,
                   $sreg_ns_uri=Auth_OpenID_SREG_NS_URI,
                   $cls='Auth_OpenID_SRegRequest')
    {
        /** @var Auth_OpenID_SRegRequest $obj */
        $obj = new $cls();

        $obj->required = array();
        $obj->optional = array();
        $obj->policy_url = $policy_url;
        $obj->ns_uri = $sreg_ns_uri;

        if ($required) {
            if (!$obj->requestFields($required, true, true)) {
                return null;
            }
        }

        if ($optional) {
            if (!$obj->requestFields($optional, false, true)) {
                return null;
            }
        }

        return $obj;
    }
213955
public static HttpRequest createRequest(Method method, String url) {
		return new HttpRequest(url).method(method);
	}
721930
function _request (method, url, options, session) {
    // require options to be object
    options = requireValidOptionalObject(options)
    // set http method
    options.method = method
    // merge arguments into options
    options.uri = url
    // make request
    return request(options, session)
}
593735
public function createRequest()
    {
        if ($this->request == null){
            $this->request = Request::fromPhpContext($this);
        }

        return $this->request;
    }
204472
public function doRequest($request)
    {
        $inputStream = fopen('php://memory', 'r+');
        $content = $request->getContent();
        if ($content !== null) {
            fwrite($inputStream, $content);
            rewind($inputStream);
        }

        $queryParams = [];
        $postParams = [];
        $queryString = parse_url($request->getUri(), PHP_URL_QUERY);
        if ($queryString != '') {
            parse_str($queryString, $queryParams);
        }
        if ($request->getMethod() !== 'GET') {
            $postParams = $request->getParameters();
        }

        $serverParams = $request->getServer();
        if (!isset($serverParams['SCRIPT_NAME'])) {
            //required by WhoopsErrorHandler
            $serverParams['SCRIPT_NAME'] = 'Codeception';
        }
        
        $cookies = $request->getCookies();
        $headers = $this->extractHeaders($request);

        //set cookie header because dflydev/fig-cookies reads cookies from header
        if (!empty($cookies)) {
            $headers['cookie'] = implode(';', array_map(function ($key, $value) {
                return "$key=$value";
            }, array_keys($cookies), $cookies));
        }

        $zendRequest = new ServerRequest(
            $serverParams,
            $this->convertFiles($request->getFiles()),
            $request->getUri(),
            $request->getMethod(),
            $inputStream,
            $headers,
            $cookies,
            $queryParams,
            $postParams
        );

        $this->request = $zendRequest;

        $cwd = getcwd();
        chdir(codecept_root_dir());

        if ($this->config['recreateApplicationBetweenRequests'] === true || $this->application === null) {
            $application = $this->initApplication();
        } else {
            $application = $this->application;
        }

        if (method_exists($application, 'handle')) {
            //Zend Expressive v3
            $response = $application->handle($zendRequest);
        } else {
            //Older versions
            $application->run($zendRequest);
            $response = $this->responseCollector->getResponse();
            $this->responseCollector->clearResponse();
        }

        chdir($cwd);

        return new Response(
            (string)$response->getBody(),
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }
125165
public function getRequest()
    {
        if (isset($_SERVER['REQUEST_METHOD'])) {
            return new PhpRequest(
                empty($_SESSION) ? [] : $_SESSION,
                empty($_COOKIE) ? [] : $_COOKIE,
                getallheaders(),
                $_SERVER,
                static::getInputParams($_SERVER, $_POST)
            );
        }

        return new NullRequest();
    }