class Env (View source)

The http\Env class provides static methods to manipulate and inspect the server's current request's HTTP environment.

Methods

getRequestBody(string $body_class_name = null)

Retrieve the current HTTP request's body.

string|null|array
getRequestHeader(string $header_name = null)

Retrieve one or all headers of the current HTTP request.

int
getResponseCode()

Get the HTTP response code to send.

string|array|null
getResponseHeader(string $header_name = null)

Get one or all HTTP response headers to be sent.

array
getResponseStatusForAllCodes()

Retrieve a list of all known HTTP response status.

string
getResponseStatusForCode(int $code)

Retrieve the string representation of specified HTTP response code.

string|null
negotiate(string $params, array $supported, string $prim_typ_sep = null, array $result = null)

Generic negotiator. For specific client negotiation see http\Env::negotiateContentType() and related methods.

string|null
negotiateCharset(array $supported, array $result = null)

Negotiate the client's preferred character set.

string|null
negotiateContentType(array $supported, array $result = null)

Negotiate the client's preferred MIME content type.

string|null
negotiateEncoding(array $supported, array $result = null)

Negotiate the client's preferred encoding.

string|null
negotiateLanguage(array $supported, array $result = null)

Negotiate the client's preferred language.

bool
setResponseCode(int $code)

Set the HTTP response code to send.

bool
setResponseHeader(string $header_name, mixed $header_value = null, int $response_code = null, bool $replace = null)

Set a response header, either replacing a prior set header, or appending the new header value, depending on $replace.

Details

Body getRequestBody(string $body_class_name = null)

Retrieve the current HTTP request's body.

Parameters

string $body_class_name

A user class extending http\Message\Body.

Return Value

Body

instance representing the request body

Exceptions

InvalidArgumentException
UnexpectedValueException

string|null|array getRequestHeader(string $header_name = null)

Retrieve one or all headers of the current HTTP request.

Parameters

string $header_name

The key of a header to retrieve.

Return Value

string|null|array

NULL if $header_name was not found or string the compound header when $header_name was found or array of all headers if $header_name was not specified

int getResponseCode()

Get the HTTP response code to send.

Return Value

int

the HTTP response code.

string|array|null getResponseHeader(string $header_name = null)

Get one or all HTTP response headers to be sent.

Parameters

string $header_name

The name of the response header to retrieve.

Return Value

string|array|null

string the compound value of the response header to send or NULL if the header was not found or array of all response headers, if $header_name was not specified

array getResponseStatusForAllCodes()

Retrieve a list of all known HTTP response status.

Return Value

array

mapping of the form [ ... int $code => string $status ... ]

string getResponseStatusForCode(int $code)

Retrieve the string representation of specified HTTP response code.

Parameters

int $code

The HTTP response code to get the string representation for.

Return Value

string

the HTTP response status message (may be empty, if no message for this code was found)

string|null negotiate(string $params, array $supported, string $prim_typ_sep = null, array $result = null)

Generic negotiator. For specific client negotiation see http\Env::negotiateContentType() and related methods.

NOTE: The first element of $supported serves as a default if no operand matches.

Parameters

string $params

HTTP header parameter's value to negotiate.

array $supported

List of supported negotiation operands.

string $prim_typ_sep

A "primary type separator", i.e. that would be a hyphen for content language negotiation (en-US, de-DE, etc.).

array $result

Out parameter recording negotiation results.

Return Value

string|null

NULL if negotiation fails. or string the closest match negotiated, or the default (first entry of $supported).

string|null negotiateCharset(array $supported, array $result = null)

Negotiate the client's preferred character set.

NOTE: The first element of $supported character sets serves as a default if no character set matches.

Parameters

array $supported

List of supported content character sets.

array $result

Out parameter recording negotiation results.

Return Value

string|null

NULL if negotiation fails. or string the negotiated character set.

string|null negotiateContentType(array $supported, array $result = null)

Negotiate the client's preferred MIME content type.

NOTE: The first element of $supported content types serves as a default if no content-type matches.

Parameters

array $supported

List of supported MIME content types.

array $result

Out parameter recording negotiation results.

Return Value

string|null

NULL if negotiation fails. or string the negotiated content type.

string|null negotiateEncoding(array $supported, array $result = null)

Negotiate the client's preferred encoding.

NOTE: The first element of $supported encodings serves as a default if no encoding matches.

Parameters

array $supported

List of supported content encodings.

array $result

Out parameter recording negotiation results.

Return Value

string|null

NULL if negotiation fails. or string the negotiated encoding.

string|null negotiateLanguage(array $supported, array $result = null)

Negotiate the client's preferred language.

NOTE: The first element of $supported languages serves as a default if no language matches.

Parameters

array $supported

List of supported content languages.

array $result

Out parameter recording negotiation results.

Return Value

string|null

NULL if negotiation fails. or string the negotiated language.

bool setResponseCode(int $code)

Set the HTTP response code to send.

Parameters

int $code

The HTTP response status code.

Return Value

bool Success.

bool setResponseHeader(string $header_name, mixed $header_value = null, int $response_code = null, bool $replace = null)

Set a response header, either replacing a prior set header, or appending the new header value, depending on $replace.

If no $header_value is specified, or $header_value is NULL, then a previously set header with the same key will be deleted from the list.

If $response_code is not 0, the response status code is updated accordingly.

Parameters

string $header_name
mixed $header_value
int $response_code
bool $replace

Return Value

bool Success.