class ServerRequestFactory (View source)

The ServerRequestFactory class.

Properties

static callable $apacheRequestHeaders Function name to get apache request headers. This property is for test use.

Methods

static ServerRequestInterface
createFromGlobals(array $server = array(), array $query = array(), array $parsedBody = null, array $cookies = array(), array $files = array())

Create a request from the supplied superglobal values.

static ServerRequestInterface
createFromUri(string $uri, string $script = null, array $server = array(), array $query = array(), array $parsedBody = null, array $cookies = array(), array $files = array())

createFromUri

static array
prepareServers(array $server)

Prepare the $_SERVER variables.

static UploadedFileInterface[]
prepareFiles(array $files)

Normalize uploaded files

static array
prepareHeaders(array $server)

Get headers from $_SERVER.

static PsrUri
prepareUri(array $server, array $headers)

Marshal the URI from the $_SERVER array and headers

static 
getHostAndPortFromHeaders(string $host, string $port, array $server, array $headers)

Marshal the host and port from HTTP headers and/or the PHP environment

static string
getRequestUri(array $server)

Get the base URI for the $_SERVER superglobal.

static string
stripQueryString(string $path)

Strip the query string from a path

Details

at line line 54
static ServerRequestInterface createFromGlobals(array $server = array(), array $query = array(), array $parsedBody = null, array $cookies = array(), array $files = array())

Create a request from the supplied superglobal values.

If any argument is not supplied, the corresponding superglobal value will be used.

The ServerRequest created is then passed to the fromServer() method in order to marshal the request URI and headers.

Parameters

array $server The $_SERVER superglobal variable.
array $query The $_GET superglobal variable.
array $parsedBody The $_POST superglobal variable.
array $cookies The $_COOKIE superglobal variable.
array $files The $_FILES superglobal variable.

Return Value

ServerRequestInterface

Exceptions

InvalidArgumentException for invalid file values

See also

fromServer()

at line line 110
static ServerRequestInterface createFromUri(string $uri, string $script = null, array $server = array(), array $query = array(), array $parsedBody = null, array $cookies = array(), array $files = array())

createFromUri

Parameters

string $uri
string $script
array $server
array $query
array $parsedBody
array $cookies
array $files

Return Value

ServerRequestInterface

at line line 134
static array prepareServers(array $server)

Prepare the $_SERVER variables.

Parameters

array $server The $_SERVER superglobal variable.

Return Value

array

at line line 168
static UploadedFileInterface[] prepareFiles(array $files)

Normalize uploaded files

Transforms each value into an UploadedFileInterface instance, and ensures that nested arrays are normalized.

Parameters

array $files THe $_FILES superglobal variable.

Return Value

UploadedFileInterface[]

Exceptions

InvalidArgumentException for unrecognized values

at line line 210
static array prepareHeaders(array $server)

Get headers from $_SERVER.

Parameters

array $server The $_SERVER superglobal variable.

Return Value

array

at line line 249
static PsrUri prepareUri(array $server, array $headers)

Marshal the URI from the $_SERVER array and headers

Parameters

array $server The $_SERVER superglobal.
array $headers The headers variable from server.

Return Value

PsrUri Prepared Uri object.

at line line 305
static getHostAndPortFromHeaders(string $host, string $port, array $server, array $headers)

Marshal the host and port from HTTP headers and/or the PHP environment

Parameters

string $host The uri host.
string $port The request port.
array $server The $_SERVER superglobal.
array $headers The headers variable from server.

at line line 359
static string getRequestUri(array $server)

Get the base URI for the $_SERVER superglobal.

Try to auto detect the base URI from different server system including IIS and Apache.

This method based on ZF2's Zend\Http\PhpEnvironment\Request class

Parameters

array $server

Return Value

string

See also

https://github.com/zendframework/zend-http/blob/master/src/PhpEnvironment/Request.php

at line line 411
static string stripQueryString(string $path)

Strip the query string from a path

Parameters

string $path The uri path.

Return Value

string The path striped.