Loading…

HttpMessage

PSR-7 (HttpMessage) & PSR-17 (HttpFactory) Implementations

Notable features

  • Ability to register per-media-type custom body parsers
  • By default the following parsers are registered
    • application/x-www-form-urlencoded - Preserves "." and space in keys
    • application/json - decoded to array
    • application/xml, text/xml parsed to SimpleXMLElement obj
  • parsedBody and queryParams preserves "." and spaces in keys
  • UploadedFile::getClientFullPath(). PHP 8.1 added a new file upload property (not included in PSR-7)
  • ServerRequestExtended interface and implementation - Extends standard server request with helpful methods

Utilities

  • ContentType: common mime-type constants
  • HttpFoundationBridge: create ServerRequest and Response from HttpFoundation request and response
  • ParseStr: PHP's parse_str(), but does not convert dots and spaces to '_' by default
  • Response:
    • emit(ResponseInterface $response) - Output response headers and body
    • codePhrase(int|string $code): string - Get standard code phrase for given HTTP status code
  • ServerRequest:
    • fromGlobals(): ServerRequestInterface
  • Stream
    • getContent(StreamInterface): string - Get stream contents without affecting pointer
  • Uri:
    • fromGlobals(): UriInterface
    • fromParsed(array): UriInterface
    • isCrossOrigin(UriInterface $uri1, UriInterface $uri2): bool
    • parseUrl(string|UriInterface): array - like php's parse_url but with bug fixes backported
    • resolve(UriInterface $base, UriInterface $rel): UriInterface - Converts the relative URI into a new URI that is resolved against the base URI.

Installation

composer require bdk/http-message

Documentation

http://bradkent.com/php/httpmessage

3 maintained versions:

Version http-message http-factory php note
3.x ^1.1 | ^2.0 ^1.0 >= 8.0 static returns
2.x ^1.1 | ^2.0 ^1.0 >= 7.2 self returns
1.x ~1.0.1 -- >= 5.4  

Tests / Quality

Supported PHP versions
Build Status
Maintainability
Coverage

Classes

bdk\HttpMessage\Message

Http Message

HTTP messages consist of requests from a client to a server and responses from a server to a client. This interface defines the methods common to each.

Messages are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return an instance that contains the changed state.

Implements

    Psr\Http\Message\MessageInterface

Methods

getBody(): Psr\Http\Message\StreamInterface

Gets the body of the message.

Return Value
Psr\Http\Message\StreamInterface
The body as a stream.
getHeader(string $name): string[]

Retrieves a message header value by the given case-insensitive name.

Description

This method returns an array of all the header values of the given case-insensitive header name.

Parameters
name
header name
Return Value
string[]
An array of string values as provided for the given header. If the header does not appear in the message, an empty array is returned.
getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

Description

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method will return an empty string.

Parameters
name
Case-insensitive header field name.
Return Value
string
A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method will return an empty string.
getHeaders(): string[][]

Retrieves all message header values.

Description

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Return Value
string[][]
Returns an associative array of the message's headers. Each key is a header name, and each value is an array of strings for that header.
getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

Return Value
string
HTTP protocol version (e.g., "1.1", "1.0").
hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

Parameters
name
Case-insensitive header field name.
Return Value
bool
Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
withAddedHeader(string $name, string|string[] $value): static

Return an instance with the specified header values appended to the current value

Description

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

Parameters
name
Case-insensitive header field name to add.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withBody(Psr\Http\Message\StreamInterface $body): static

Return an instance with the specified message body.

Parameters
body
Body
Return Value
static
withHeader(string $name, string|string[] $value): static

Return an instance with the provided value replacing the specified header.

Parameters
name
Case-insensitive header field name.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withoutHeader(string $name): static

Return an instance without the specified header.

Parameters
name
Case-insensitive header field name to remove.
Return Value
static
withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

Description

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Parameters
version
HTTP protocol version
Return Value
static

bdk\HttpMessage\Request

Representation of an outgoing, client-side request.

Per the HTTP specification, this class includes properties for each of the following:

  • Protocol version
  • HTTP method
  • URI
  • Headers
  • Message body

Requests are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return an instance that contains the changed state.

Extends

    bdk\HttpMessage\Message

Implements

  • Psr\Http\Message\RequestInterface
    • Psr\Http\Message\MessageInterface

Methods

__construct(string $method = GET[, Psr\Http\Message\UriInterface|string $uri = ])

Constructor

Parameters
method
The HTTP method associated with the request.
uri
The URI associated with the request.
phpDoc
throws: InvalidArgumentException
getMethod(): string

Retrieves the HTTP method of the request.

Return Value
string
Returns the request method.
getRequestTarget(): string

Retrieves the message's request target.

Description

Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).

In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).

If no URI is available, and no request-target has been specifically provided, this method will return the string "/".

Return Value
string
getUri(): Psr\Http\Message\UriInterface

Retrieves the URI instance.

Return Value
Psr\Http\Message\UriInterface
Returns a UriInterface instance representing the URI of the request.
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
withMethod(string $method): static

Return an instance with the provided HTTP method.

Description

Standard methods include: HEAD: Asks for a response identical to that of a GET request, but without the response body. GET: Requests a representation of the specified resource Requests using GET should only retrieve data. POST: Submit an entity to the specified resource, Often causing a change in state or side effects on the server. PUT: Replaces all current representations of the target resource with the request payload. DELETE: Deletes the specified resource. PATCH: Used to apply partial modifications to a resource. CONNECT: Establishes a tunnel to the server identified by the target resource. OPTIONS: Used to describe the communication options for the target resource. TRACE: Performs a message loop-back test along the path to the target resource.

Parameters
method
Case-sensitive method.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc7231
throws: for invalid HTTP methods. InvalidArgumentException
withRequestTarget(string $requestTarget): static

Return an instance with the specific request-target.

Description

If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.

Parameters
requestTarget
new request target
Return Value
static
phpDoc
see: (for the various request-target forms allowed in request messages)
throws: InvalidArgumentException
withUri(Psr\Http\Message\UriInterface $uri[, bool $preserveHost = false]): static

Returns an instance with the provided URI.

Description

This method will update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.

You can opt-in to preserving the original state of the Host header by setting $preserveHost to true. When $preserveHost is set to true, this method interacts with the Host header in the following ways:

  • If the Host header is missing or empty, and the new URI contains a host component, this method will update the Host header in the returned request.
  • If the Host header is missing or empty, and the new URI does not contain a host component, this method will NOT update the Host header in the returned request.
  • If a Host header is present and non-empty, this method will NOT update the Host header in the returned request.
Parameters
uri
New request URI to use.
preserveHost
Preserve the original state of the Host header.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
throws: InvalidArgumentException
Inherited from bdk\HttpMessage\Message
getBody(): Psr\Http\Message\StreamInterface

Gets the body of the message.

Return Value
Psr\Http\Message\StreamInterface
The body as a stream.
getHeader(string $name): string[]

Retrieves a message header value by the given case-insensitive name.

Description

This method returns an array of all the header values of the given case-insensitive header name.

Parameters
name
header name
Return Value
string[]
An array of string values as provided for the given header. If the header does not appear in the message, an empty array is returned.
getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

Description

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method will return an empty string.

Parameters
name
Case-insensitive header field name.
Return Value
string
A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method will return an empty string.
getHeaders(): string[][]

Retrieves all message header values.

Description

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Return Value
string[][]
Returns an associative array of the message's headers. Each key is a header name, and each value is an array of strings for that header.
getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

Return Value
string
HTTP protocol version (e.g., "1.1", "1.0").
hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

Parameters
name
Case-insensitive header field name.
Return Value
bool
Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
withAddedHeader(string $name, string|string[] $value): static

Return an instance with the specified header values appended to the current value

Description

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

Parameters
name
Case-insensitive header field name to add.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withBody(Psr\Http\Message\StreamInterface $body): static

Return an instance with the specified message body.

Parameters
body
Body
Return Value
static
withHeader(string $name, string|string[] $value): static

Return an instance with the provided value replacing the specified header.

Parameters
name
Case-insensitive header field name.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withoutHeader(string $name): static

Return an instance without the specified header.

Parameters
name
Case-insensitive header field name to remove.
Return Value
static
withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

Description

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Parameters
version
HTTP protocol version
Return Value
static

bdk\HttpMessage\Response

Http Response

Representation of an outgoing, server-side response.

Per the HTTP specification, this class includes properties for each of the following:

  • Protocol version
  • Status code and reason phrase
  • Headers
  • Message body

Responses are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return an instance that contains the changed state.

Extends

    bdk\HttpMessage\Message

Implements

  • Psr\Http\Message\ResponseInterface
    • Psr\Http\Message\MessageInterface

Methods

__construct(int $code = 200[, string $reasonPhrase = ])

Constructor

Parameters
code
The HTTP status code. Defaults to 200.
reasonPhrase
The reason phrase to associate with the status code Defaults to standard phrase for given code
getReasonPhrase(): string

Gets the response reason phrase associated with the status code.

Return Value
string
Reason phrase; must return an empty string if none present.
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc7231#section-6
see: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
getStatusCode(): int

Gets the response status code.

Description

The status code is a 3-digit integer result code of the server's attempt to understand and satisfy the request.

Return Value
int
Status code.
withStatus(int $code[, string $reasonPhrase = ]): static

Return an instance with the specified status code and, optionally, reason phrase.

Description

If no reason phrase is specified, implementations MAY choose to default to the RFC 7231 or IANA recommended reason phrase for the response's status code.

Parameters
code
The 3-digit integer result code to set.
reasonPhrase
The reason phrase to use with the provided status code; if none is provided, implementations MAY use the defaults as suggested in the HTTP specification.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc7231#section-6
see: http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
throws: For invalid status code arguments. InvalidArgumentException
Inherited from bdk\HttpMessage\Message
getBody(): Psr\Http\Message\StreamInterface

Gets the body of the message.

Return Value
Psr\Http\Message\StreamInterface
The body as a stream.
getHeader(string $name): string[]

Retrieves a message header value by the given case-insensitive name.

Description

This method returns an array of all the header values of the given case-insensitive header name.

Parameters
name
header name
Return Value
string[]
An array of string values as provided for the given header. If the header does not appear in the message, an empty array is returned.
getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

Description

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method will return an empty string.

Parameters
name
Case-insensitive header field name.
Return Value
string
A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method will return an empty string.
getHeaders(): string[][]

Retrieves all message header values.

Description

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Return Value
string[][]
Returns an associative array of the message's headers. Each key is a header name, and each value is an array of strings for that header.
getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

Return Value
string
HTTP protocol version (e.g., "1.1", "1.0").
hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

Parameters
name
Case-insensitive header field name.
Return Value
bool
Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
withAddedHeader(string $name, string|string[] $value): static

Return an instance with the specified header values appended to the current value

Description

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

Parameters
name
Case-insensitive header field name to add.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withBody(Psr\Http\Message\StreamInterface $body): static

Return an instance with the specified message body.

Parameters
body
Body
Return Value
static
withHeader(string $name, string|string[] $value): static

Return an instance with the provided value replacing the specified header.

Parameters
name
Case-insensitive header field name.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withoutHeader(string $name): static

Return an instance without the specified header.

Parameters
name
Case-insensitive header field name to remove.
Return Value
static
withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

Description

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Parameters
version
HTTP protocol version
Return Value
static

bdk\HttpMessage\ServerRequest

Representation of an incoming, server-side HTTP request.

Per the HTTP specification, this class includes properties for each of the following:

  • Protocol version
  • HTTP method
  • URI
  • Headers
  • Message body

Additionally, it encapsulates all data as it has arrived to the application from the CGI and/or PHP environment, including:

  • The values represented in $_SERVER.
  • Any cookies provided (generally via $_COOKIE)
  • Query string arguments (generally via $_GET, or as parsed via parse_str())
  • Upload files, if any (as represented by $_FILES)
  • Deserialized body parameters (generally from $_POST)

$_SERVER values are treated as immutable, as they represent application state at the time of request; as such, no methods are provided to allow modification of those values. The other values provide such methods, as they can be restored from $_SERVER or the request body, and may need treatment during the application (e.g., body parameters may be deserialized based on content type).

Additionally, this class recognizes the utility of introspecting a request to derive and match additional parameters (e.g., via URI path matching, decrypting cookie values, deserializing non-form-encoded body content, matching authorization headers to users, etc). These parameters are stored in an "attributes" property.

Requests are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return an instance that contains the changed state.

Extends

    bdk\HttpMessage\Request
    bdk\HttpMessage\Message

Implements

  • Psr\Http\Message\ServerRequestInterface
    • Psr\Http\Message\RequestInterface
      • Psr\Http\Message\MessageInterface

Methods

__construct(string $method = GET[, Psr\Http\Message\UriInterface|string $uri = [, array $serverParams = array()]])

Constructor

Parameters
method
The HTTP method associated with the request.
uri
The URI associated with the request.
serverParams
An array of Server API (SAPI) parameters with which to seed the generated request instance. (and headers)
static fromGlobals(array $parseStrOpts = array()): bdk\HttpMessage\ServerRequest

Instantiate self from superglobals

Parameters
parseStrOpts
Parse options (default: {convDot:false, convSpace:false})
Return Value
bdk\HttpMessage\ServerRequest
getAttribute(string $name[, mixed $default = null]): mixed

Retrieve a single derived request attribute.

Parameters
name
The attribute name.
default
Default value to return if the attribute does not exist.
Return Value
mixed
getAttributes(): mixed[]

Retrieve attributes derived from the request.

Description

The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.

Return Value
mixed[]
Attributes derived from the request.
getCookieParams(): array

Get Cookie values

Return Value
array
getParsedBody(): null|array|object

Get $_POST data

Return Value
null|array|object
getQueryParams(): array

Get $_GET data

Return Value
array
getServerParams(): array

Get $_SERVER values

Return Value
array
getUploadedFiles(): array

Retrieve normalized file upload data.

Description

This method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.

Return Value
array
An array tree of UploadedFileInterface instances (or an empty array)
registerMediaTypeParser(string $contentType, callable $callable): static

Register media type parser.

Description

Define a custom body parser for a specific media type.

Note: This method is not part of the PSR-7 standard.
Parameters
contentType
A HTTP media type (excluding content-type params).
callable
A callable that returns parsed contents for media type.
Return Value
static
withAttribute(string $name, mixed $value): static

Return an instance with the specified derived request attribute.

Parameters
name
attribute name
value
value
Return Value
static
withCookieParams(array $cookies): static

Return an instance with the specified cookies.

Parameters
cookies
$_COOKIE
Return Value
static
withoutAttribute(string $name): static

Return an instance that removes the specified derived request attribute.

Parameters
name
attribute name
Return Value
static
withParsedBody(null|array|object $data): static

Return an instance with the specified body parameters.

Parameters
data
The deserialized body data ($_POST). This will typically be in an array or object
Return Value
static
withQueryParams(array $query): static

Return an instance with the specified query string arguments.

Parameters
query
Array of query string arguments, typically from $_GET.
Return Value
static
withUploadedFiles(array $uploadedFiles): static

Create a new instance with the specified uploaded files.

Parameters
uploadedFiles
An array tree of UploadedFileInterface instances.
Return Value
static
phpDoc
throws: if an invalid structure is provided. InvalidArgumentException
Inherited from bdk\HttpMessage\Request
getMethod(): string

Retrieves the HTTP method of the request.

Return Value
string
Returns the request method.
getRequestTarget(): string

Retrieves the message's request target.

Description

Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).

In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).

If no URI is available, and no request-target has been specifically provided, this method will return the string "/".

Return Value
string
getUri(): Psr\Http\Message\UriInterface

Retrieves the URI instance.

Return Value
Psr\Http\Message\UriInterface
Returns a UriInterface instance representing the URI of the request.
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
withMethod(string $method): static

Return an instance with the provided HTTP method.

Description

Standard methods include: HEAD: Asks for a response identical to that of a GET request, but without the response body. GET: Requests a representation of the specified resource Requests using GET should only retrieve data. POST: Submit an entity to the specified resource, Often causing a change in state or side effects on the server. PUT: Replaces all current representations of the target resource with the request payload. DELETE: Deletes the specified resource. PATCH: Used to apply partial modifications to a resource. CONNECT: Establishes a tunnel to the server identified by the target resource. OPTIONS: Used to describe the communication options for the target resource. TRACE: Performs a message loop-back test along the path to the target resource.

Parameters
method
Case-sensitive method.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc7231
throws: for invalid HTTP methods. InvalidArgumentException
withoutHeader(string $name): static

Return an instance without the specified header.

Parameters
name
Case-insensitive header field name to remove.
Return Value
static
withRequestTarget(string $requestTarget): static

Return an instance with the specific request-target.

Description

If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.

Parameters
requestTarget
new request target
Return Value
static
phpDoc
see: (for the various request-target forms allowed in request messages)
throws: InvalidArgumentException
withUri(Psr\Http\Message\UriInterface $uri[, bool $preserveHost = false]): static

Returns an instance with the provided URI.

Description

This method will update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.

You can opt-in to preserving the original state of the Host header by setting $preserveHost to true. When $preserveHost is set to true, this method interacts with the Host header in the following ways:

  • If the Host header is missing or empty, and the new URI contains a host component, this method will update the Host header in the returned request.
  • If the Host header is missing or empty, and the new URI does not contain a host component, this method will NOT update the Host header in the returned request.
  • If a Host header is present and non-empty, this method will NOT update the Host header in the returned request.
Parameters
uri
New request URI to use.
preserveHost
Preserve the original state of the Host header.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
throws: InvalidArgumentException
Inherited from bdk\HttpMessage\Message
getBody(): Psr\Http\Message\StreamInterface

Gets the body of the message.

Return Value
Psr\Http\Message\StreamInterface
The body as a stream.
getHeader(string $name): string[]

Retrieves a message header value by the given case-insensitive name.

Description

This method returns an array of all the header values of the given case-insensitive header name.

Parameters
name
header name
Return Value
string[]
An array of string values as provided for the given header. If the header does not appear in the message, an empty array is returned.
getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

Description

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method will return an empty string.

Parameters
name
Case-insensitive header field name.
Return Value
string
A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method will return an empty string.
getHeaders(): string[][]

Retrieves all message header values.

Description

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Return Value
string[][]
Returns an associative array of the message's headers. Each key is a header name, and each value is an array of strings for that header.
getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

Return Value
string
HTTP protocol version (e.g., "1.1", "1.0").
hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

Parameters
name
Case-insensitive header field name.
Return Value
bool
Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
withAddedHeader(string $name, string|string[] $value): static

Return an instance with the specified header values appended to the current value

Description

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

Parameters
name
Case-insensitive header field name to add.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withBody(Psr\Http\Message\StreamInterface $body): static

Return an instance with the specified message body.

Parameters
body
Body
Return Value
static
withHeader(string $name, string|string[] $value): static

Return an instance with the provided value replacing the specified header.

Parameters
name
Case-insensitive header field name.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

Description

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Parameters
version
HTTP protocol version
Return Value
static

bdk\HttpMessage\ServerRequestExtended

Extends standard server request with helpful methods

Note: This class is not part of the PSR-7 standard.

Extends

    bdk\HttpMessage\ServerRequest
    bdk\HttpMessage\Request
    bdk\HttpMessage\Message

Implements

  • bdk\HttpMessage\ServerRequestExtendedInterface
    • Psr\Http\Message\ServerRequestInterface
      • Psr\Http\Message\RequestInterface
        • Psr\Http\Message\MessageInterface

Methods

static fromServerRequest(Psr\Http\Message\ServerRequestInterface $serverRequest): ServerRequestExtendedInterface

Create a ServerRequestExtended object from ServerRequest

Description

If a ServerRequestExtendedInterface instance is passed to this method, Implementation should return it unmodified.

Note: This method is not part of the PSR-7 standard.
Parameters
serverRequest
ServerRequest instance
Return Value
ServerRequestExtendedInterface
getCookieParam(string $key[, mixed $default = null]): mixed

Fetch cookie value from cookies sent by the client to the server.

Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The attribute name.
default
Default value to return if the cookie value does not exist.
Return Value
mixed
getMediaType(): string|null

Get serverRequest media type, if known.

Description

Parses the Content-Type header and returns the "media type"

example: Content-Type: multipart/form-data; Charset=UTF-8; boundary=ExampleBoundaryString

getMediaType() will return "multipart/form-data"

Note: This method is not part of the PSR-7 standard.
Return Value
string|null
The serverRequest media type, minus content-type params
getMediaTypeParams(): string[]

Get serverRequest media type params, if known.

Description

Parses and returns the parameters found after the "media type" in the Content-Type header.

example: Content-Type: multipart/form-data; Charset=UTF-8; boundary=ExampleBoundaryString

getMediaTypeParams() will return

[
  'charset' => 'utf-8',
  'boundary' => 'ExampleBoundaryString'
]
Note: This method is not part of the PSR-7 standard.
Return Value
string[]
phpDoc
getParam(string $key[, string $default = null]): mixed

Fetch request parameter value from body or query string (in that order).

Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The parameter key.
default
The default value.
Return Value
mixed
The parameter value.
getParams(): array

Fetch associative array of body and query string parameters.

Description
Note: This method is not part of the PSR-7 standard.
Return Value
array
getParsedBodyParam(string $key[, mixed $default = null]): mixed

Fetch parameter value from request body.

Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The param key.
default
The default value
Return Value
mixed
Body param value, or $default if not set
getQueryParam(string $key[, mixed $default = null]): mixed

Fetch parameter value from query string.

Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The param key
default
The default value
Return Value
mixed
Body query param value, or $default if not set
getServerParam(string $key[, mixed $default = null]): mixed

Retrieve a server parameter.

Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The Param key
default
The default value
Return Value
mixed
Server param value, or $default if not set
isSecure(): bool

Is this a secured request?

Description
Note: This method is not part of the PSR-7 standard.
Return Value
bool
isXhr(): bool

Is this an XHR (aka ajax) request?

Description
Note: This method is not part of the PSR-7 standard.
Return Value
bool
withAttributes(array<string,mixed> $attributes): static

Create a new instance with the specified attributes.

Description

This method allows setting multiple derived request attributes as described in getAttributes().

This method is implemented in such a way as to retain the immutability of the message, and returns an instance that has the upserted attributes.

Note: This method is not part of the PSR-7 standard.
Parameters
attributes
New attributes
Return Value
static
Inherited from bdk\HttpMessage\ServerRequest
__construct(string $method = GET[, Psr\Http\Message\UriInterface|string $uri = [, array $serverParams = array()]])

Constructor

Parameters
method
The HTTP method associated with the request.
uri
The URI associated with the request.
serverParams
An array of Server API (SAPI) parameters with which to seed the generated request instance. (and headers)
static fromGlobals(array $parseStrOpts = array()): bdk\HttpMessage\ServerRequest

Instantiate self from superglobals

Parameters
parseStrOpts
Parse options (default: {convDot:false, convSpace:false})
Return Value
bdk\HttpMessage\ServerRequest
getAttribute(string $name[, mixed $default = null]): mixed

Retrieve a single derived request attribute.

Parameters
name
The attribute name.
default
Default value to return if the attribute does not exist.
Return Value
mixed
getAttributes(): mixed[]

Retrieve attributes derived from the request.

Description

The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.

Return Value
mixed[]
Attributes derived from the request.
getCookieParams(): array

Get Cookie values

Return Value
array
getParsedBody(): null|array|object

Get $_POST data

Return Value
null|array|object
getQueryParams(): array

Get $_GET data

Return Value
array
getServerParams(): array

Get $_SERVER values

Return Value
array
getUploadedFiles(): array

Retrieve normalized file upload data.

Description

This method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.

Return Value
array
An array tree of UploadedFileInterface instances (or an empty array)
registerMediaTypeParser(string $contentType, callable $callable): static

Register media type parser.

Description

Define a custom body parser for a specific media type.

Note: This method is not part of the PSR-7 standard.
Parameters
contentType
A HTTP media type (excluding content-type params).
callable
A callable that returns parsed contents for media type.
Return Value
static
withAttribute(string $name, mixed $value): static

Return an instance with the specified derived request attribute.

Parameters
name
attribute name
value
value
Return Value
static
withBody(Psr\Http\Message\StreamInterface $body): static

Return an instance with the specified message body.

Parameters
body
Body
Return Value
static
withCookieParams(array $cookies): static

Return an instance with the specified cookies.

Parameters
cookies
$_COOKIE
Return Value
static
withoutAttribute(string $name): static

Return an instance that removes the specified derived request attribute.

Parameters
name
attribute name
Return Value
static
withParsedBody(null|array|object $data): static

Return an instance with the specified body parameters.

Parameters
data
The deserialized body data ($_POST). This will typically be in an array or object
Return Value
static
withQueryParams(array $query): static

Return an instance with the specified query string arguments.

Parameters
query
Array of query string arguments, typically from $_GET.
Return Value
static
withUploadedFiles(array $uploadedFiles): static

Create a new instance with the specified uploaded files.

Parameters
uploadedFiles
An array tree of UploadedFileInterface instances.
Return Value
static
phpDoc
throws: if an invalid structure is provided. InvalidArgumentException
Inherited from bdk\HttpMessage\Request
getMethod(): string

Retrieves the HTTP method of the request.

Return Value
string
Returns the request method.
getRequestTarget(): string

Retrieves the message's request target.

Description

Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).

In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).

If no URI is available, and no request-target has been specifically provided, this method will return the string "/".

Return Value
string
getUri(): Psr\Http\Message\UriInterface

Retrieves the URI instance.

Return Value
Psr\Http\Message\UriInterface
Returns a UriInterface instance representing the URI of the request.
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
withMethod(string $method): static

Return an instance with the provided HTTP method.

Description

Standard methods include: HEAD: Asks for a response identical to that of a GET request, but without the response body. GET: Requests a representation of the specified resource Requests using GET should only retrieve data. POST: Submit an entity to the specified resource, Often causing a change in state or side effects on the server. PUT: Replaces all current representations of the target resource with the request payload. DELETE: Deletes the specified resource. PATCH: Used to apply partial modifications to a resource. CONNECT: Establishes a tunnel to the server identified by the target resource. OPTIONS: Used to describe the communication options for the target resource. TRACE: Performs a message loop-back test along the path to the target resource.

Parameters
method
Case-sensitive method.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc7231
throws: for invalid HTTP methods. InvalidArgumentException
withoutHeader(string $name): static

Return an instance without the specified header.

Parameters
name
Case-insensitive header field name to remove.
Return Value
static
withRequestTarget(string $requestTarget): static

Return an instance with the specific request-target.

Description

If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.

Parameters
requestTarget
new request target
Return Value
static
phpDoc
see: (for the various request-target forms allowed in request messages)
throws: InvalidArgumentException
withUri(Psr\Http\Message\UriInterface $uri[, bool $preserveHost = false]): static

Returns an instance with the provided URI.

Description

This method will update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.

You can opt-in to preserving the original state of the Host header by setting $preserveHost to true. When $preserveHost is set to true, this method interacts with the Host header in the following ways:

  • If the Host header is missing or empty, and the new URI contains a host component, this method will update the Host header in the returned request.
  • If the Host header is missing or empty, and the new URI does not contain a host component, this method will NOT update the Host header in the returned request.
  • If a Host header is present and non-empty, this method will NOT update the Host header in the returned request.
Parameters
uri
New request URI to use.
preserveHost
Preserve the original state of the Host header.
Return Value
static
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
throws: InvalidArgumentException
Inherited from bdk\HttpMessage\Message
getBody(): Psr\Http\Message\StreamInterface

Gets the body of the message.

Return Value
Psr\Http\Message\StreamInterface
The body as a stream.
getHeader(string $name): string[]

Retrieves a message header value by the given case-insensitive name.

Description

This method returns an array of all the header values of the given case-insensitive header name.

Parameters
name
header name
Return Value
string[]
An array of string values as provided for the given header. If the header does not appear in the message, an empty array is returned.
getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

Description

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method will return an empty string.

Parameters
name
Case-insensitive header field name.
Return Value
string
A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method will return an empty string.
getHeaders(): string[][]

Retrieves all message header values.

Description

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message-&gt;getHeaders() as $name =&gt; $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message-&gt;getHeaders() as $name =&gt; $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Return Value
string[][]
Returns an associative array of the message's headers. Each key is a header name, and each value is an array of strings for that header.
getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

Return Value
string
HTTP protocol version (e.g., "1.1", "1.0").
hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

Parameters
name
Case-insensitive header field name.
Return Value
bool
Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
withAddedHeader(string $name, string|string[] $value): static

Return an instance with the specified header values appended to the current value

Description

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

Parameters
name
Case-insensitive header field name to add.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withHeader(string $name, string|string[] $value): static

Return an instance with the provided value replacing the specified header.

Parameters
name
Case-insensitive header field name.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header name or value InvalidArgumentException
withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

Description

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Parameters
version
HTTP protocol version
Return Value
static

bdk\HttpMessage\ServerRequestExtendedInterface

Extends standard server request with helpful methods

modifiers
abstract
interface
Note: This interface is not part of the PSR-7 standard.

Extends

  • Psr\Http\Message\ServerRequestInterface
    • Psr\Http\Message\RequestInterface
      • Psr\Http\Message\MessageInterface

Methods

static fromServerRequest(Psr\Http\Message\ServerRequestInterface $serverRequest): ServerRequestExtendedInterface

Create a ServerRequestExtended object from ServerRequest

modifiers
abstract
Description

If a ServerRequestExtendedInterface instance is passed to this method, Implementation should return it unmodified.

Note: This method is not part of the PSR-7 standard.
Parameters
serverRequest
ServerRequest instance
Return Value
ServerRequestExtendedInterface
getCookieParam(string $key[, mixed $default = null]): mixed

Fetch cookie value from cookies sent by the client to the server.

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The attribute name.
default
Default value to return if the cookie value does not exist.
Return Value
mixed
getMediaType(): string|null

Get serverRequest media type, if known.

modifiers
abstract
Description

Parses the Content-Type header and returns the "media type"

example: Content-Type: multipart/form-data; Charset=UTF-8; boundary=ExampleBoundaryString

getMediaType() will return "multipart/form-data"

Note: This method is not part of the PSR-7 standard.
Return Value
string|null
The serverRequest media type, minus content-type params
getMediaTypeParams(): string[]

Get serverRequest media type params, if known.

modifiers
abstract
Description

Parses and returns the parameters found after the "media type" in the Content-Type header.

example: Content-Type: multipart/form-data; Charset=UTF-8; boundary=ExampleBoundaryString

getMediaTypeParams() will return

[
  'charset' =&gt; 'utf-8',
  'boundary' =&gt; 'ExampleBoundaryString'
]
Note: This method is not part of the PSR-7 standard.
Return Value
string[]
phpDoc
getParam(string $key[, string $default = null]): mixed

Fetch request parameter value from body or query string (in that order).

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The parameter key.
default
The default value.
Return Value
mixed
The parameter value.
getParams(): array

Fetch associative array of body and query string parameters.

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Return Value
array
getParsedBodyParam(string $key[, mixed $default = null]): mixed

Fetch parameter value from request body.

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The param key.
default
The default value
Return Value
mixed
Body param value, or $default if not set
getQueryParam(string $key[, mixed $default = null]): mixed

Fetch parameter value from query string.

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The param key
default
The default value
Return Value
mixed
Body query param value, or $default if not set
getServerParam(string $key[, mixed $default = null]): mixed

Retrieve a server parameter.

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Parameters
key
The Param key
default
The default value
Return Value
mixed
Server param value, or $default if not set
isSecure(): bool

Is this a secured request?

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Return Value
bool
isXhr(): bool

Is this an XHR (aka ajax) request?

modifiers
abstract
Description
Note: This method is not part of the PSR-7 standard.
Return Value
bool
registerMediaTypeParser(string $contentType, callable $callable): static

Register media type parser.

modifiers
abstract
Description

Define a custom body parser for a specific media type.

Implementation MUST be implemented in such a way that getParsedBody() will utilize registered parsers if parsed-body not explicitly set

Note: This method is not part of the PSR-7 standard.
Parameters
contentType
A HTTP media type (excluding content-type params).
callable
A callable that receives the request body as a string and returns parsed contents
Return Value
static
withAttributes(array<string,mixed> $attributes): static

Return an instance with the specified derived request attributes.

modifiers
abstract
Description

This method allows setting multiple derived request attributes as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the upserted attributes.

Note: This method is not part of the PSR-7 standard.
Parameters
attributes
New attributes
Return Value
static
Inherited from Psr\Http\Message\ServerRequestInterface
getAttribute(string $name[, mixed $default = null]): mixed

Retrieve a single derived request attribute.

modifiers
abstract
Description

Retrieves a single derived request attribute as described in getAttributes(). If the attribute has not been previously set, returns the default value as provided.

This method obviates the need for a hasAttribute() method, as it allows specifying a default value to return if the attribute is not found.

Parameters
name
The attribute name.
default
Default value to return if the attribute does not exist.
Return Value
mixed
phpDoc
see: getAttributes()
getAttributes(): array

Retrieve attributes derived from the request.

modifiers
abstract
Description

The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.

Return Value
array
Attributes derived from the request.
getCookieParams(): array

Retrieve cookies.

modifiers
abstract
Description

Retrieves cookies sent by the client to the server.

The data MUST be compatible with the structure of the $_COOKIE superglobal.

Return Value
array
getParsedBody(): null|array|object

Retrieve any parameters provided in the request body.

modifiers
abstract
Description

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, this method MUST return the contents of $_POST.

Otherwise, this method may return any results of deserializing the request body content; as parsing returns structured content, the potential types MUST be arrays or objects only. A null value indicates the absence of body content.

Return Value
null|array|object
The deserialized body parameters, if any. These will typically be an array or object.
getQueryParams(): array

Retrieve query string arguments.

modifiers
abstract
Description

Retrieves the deserialized query string arguments, if any.

Note: the query params might not be in sync with the URI or server params. If you need to ensure you are only getting the original values, you may need to parse the query string from getUri()-&gt;getQuery() or from the QUERY_STRING server param.
Return Value
array
getServerParams(): array

Retrieve server parameters.

modifiers
abstract
Description

Retrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.

Return Value
array
getUploadedFiles(): array

Retrieve normalized file upload data.

modifiers
abstract
Description

This method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.

These values MAY be prepared from $_FILES or the message body during instantiation, or MAY be injected via withUploadedFiles().

Return Value
array
An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.
withAttribute(string $name, mixed $value): static

Return an instance with the specified derived request attribute.

modifiers
abstract
Description

This method allows setting a single derived request attribute as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated attribute.

Parameters
name
The attribute name.
value
The value of the attribute.
Return Value
static
phpDoc
see: getAttributes()
withCookieParams(array $cookies): static

Return an instance with the specified cookies.

modifiers
abstract
Description

The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST be compatible with the structure of $_COOKIE. Typically, this data will be injected at instantiation.

This method MUST NOT update the related Cookie header of the request instance, nor related values in the server params.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated cookie values.

Parameters
cookies
Array of key/value pairs representing cookies.
Return Value
static
withoutAttribute(string $name): static

Return an instance that removes the specified derived request attribute.

modifiers
abstract
Description

This method allows removing a single derived request attribute as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the attribute.

Parameters
name
The attribute name.
Return Value
static
phpDoc
see: getAttributes()
withParsedBody(null|array|object $data): static

Return an instance with the specified body parameters.

modifiers
abstract
Description

These MAY be injected during instantiation.

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, use this method ONLY to inject the contents of $_POST.

The data IS NOT REQUIRED to come from $_POST, but MUST be the results of deserializing the request body content. Deserialization/parsing returns structured data, and, as such, this method ONLY accepts arrays or objects, or a null value if nothing was available to parse.

As an example, if content negotiation determines that the request data is a JSON payload, this method could be used to create a request instance with the deserialized parameters.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated body parameters.

Parameters
data
The deserialized body data. This will typically be in an array or object.
Return Value
static
phpDoc
throws: if an unsupported argument type is provided. InvalidArgumentException
withQueryParams(array $query): static

Return an instance with the specified query string arguments.

modifiers
abstract
Description

These values SHOULD remain immutable over the course of the incoming request. They MAY be injected during instantiation, such as from PHP's $_GET superglobal, or MAY be derived from some other value such as the URI. In cases where the arguments are parsed from the URI, the data MUST be compatible with what PHP's parse_str() would return for purposes of how duplicate query parameters are handled, and how nested sets are handled.

Setting query string arguments MUST NOT change the URI stored by the request, nor the values in the server params.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated query string arguments.

Parameters
query
Array of query string arguments, typically from $_GET.
Return Value
static
withUploadedFiles(array $uploadedFiles): static

Create a new instance with the specified uploaded files.

modifiers
abstract
Description

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated body parameters.

Parameters
uploadedFiles
An array tree of UploadedFileInterface instances.
Return Value
static
phpDoc
throws: if an invalid structure is provided. InvalidArgumentException
Inherited from Psr\Http\Message\RequestInterface
getMethod(): string

Retrieves the HTTP method of the request.

modifiers
abstract
Return Value
string
Returns the request method.
getRequestTarget(): string

Retrieves the message's request target.

modifiers
abstract
Description

Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).

In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).

If no URI is available, and no request-target has been specifically provided, this method MUST return the string "/".

Return Value
string
getUri(): UriInterface

Retrieves the URI instance.

modifiers
abstract
Description

This method MUST return a UriInterface instance.

Return Value
UriInterface
Returns a UriInterface instance representing the URI of the request.
phpDoc
withMethod(string $method): static

Return an instance with the provided HTTP method.

modifiers
abstract
Description

While HTTP method names are typically all uppercase characters, HTTP method names are case-sensitive and thus implementations SHOULD NOT modify the given string.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the changed request method.

Parameters
method
Case-sensitive method.
Return Value
static
phpDoc
throws: for invalid HTTP methods. InvalidArgumentException
withRequestTarget(string $requestTarget): static

Return an instance with the specific request-target.

modifiers
abstract
Description

If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the changed request target.

Parameters
requestTarget
$requestTarget
Return Value
static
phpDoc
withUri(UriInterface $uri[, bool $preserveHost = false]): static

Returns an instance with the provided URI.

modifiers
abstract
Description

This method MUST update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.

You can opt-in to preserving the original state of the Host header by setting $preserveHost to true. When $preserveHost is set to true, this method interacts with the Host header in the following ways:

  • If the Host header is missing or empty, and the new URI contains a host component, this method MUST update the Host header in the returned request.
  • If the Host header is missing or empty, and the new URI does not contain a host component, this method MUST NOT update the Host header in the returned request.
  • If a Host header is present and non-empty, this method MUST NOT update the Host header in the returned request.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new UriInterface instance.

Parameters
uri
New request URI to use.
preserveHost
Preserve the original state of the Host header.
Return Value
static
phpDoc
Inherited from Psr\Http\Message\MessageInterface
getBody(): StreamInterface

Gets the body of the message.

modifiers
abstract
Return Value
StreamInterface
Returns the body as a stream.
getHeader(string $name): string[]

Retrieves a message header value by the given case-insensitive name.

modifiers
abstract
Description

This method returns an array of all the header values of the given case-insensitive header name.

If the header does not appear in the message, this method MUST return an empty array.

Parameters
name
Case-insensitive header field name.
Return Value
string[]
An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.
getHeaderLine(string $name): string

Retrieves a comma-separated string of the values for a single header.

modifiers
abstract
Description

This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.

NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.

If the header does not appear in the message, this method MUST return an empty string.

Parameters
name
Case-insensitive header field name.
Return Value
string
A string of values as provided for the given header concatenated together using a comma. If the header does not appear in the message, this method MUST return an empty string.
getHeaders(): string[][]

Retrieves all message header values.

modifiers
abstract
Description

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message-&gt;getHeaders() as $name =&gt; $values) {
    echo $name . ": " . implode(", ", $values);
}

// Emit headers iteratively:
foreach ($message-&gt;getHeaders() as $name =&gt; $values) {
    foreach ($values as $value) {
        header(sprintf('%s: %s', $name, $value), false);
    }
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Return Value
string[][]
Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.
getProtocolVersion(): string

Retrieves the HTTP protocol version as a string.

modifiers
abstract
Description

The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

Return Value
string
HTTP protocol version.
hasHeader(string $name): bool

Checks if a header exists by the given case-insensitive name.

modifiers
abstract
Parameters
name
Case-insensitive header field name.
Return Value
bool
Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
withAddedHeader(string $name, string|string[] $value): static

Return an instance with the specified header appended with the given value.

modifiers
abstract
Description

Existing values for the specified header will be maintained. The new value(s) will be appended to the existing list. If the header did not exist previously, it will be added.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new header and/or value.

Parameters
name
Case-insensitive header field name to add.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header names or values. InvalidArgumentException
withBody(StreamInterface $body): static

Return an instance with the specified message body.

modifiers
abstract
Description

The body MUST be a StreamInterface object.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the new body stream.

Parameters
body
Body.
Return Value
static
phpDoc
throws: When the body is not valid. InvalidArgumentException
withHeader(string $name, string|string[] $value): static

Return an instance with the provided value replacing the specified header.

modifiers
abstract
Description

While header names are case-insensitive, the casing of the header will be preserved by this function, and returned from getHeaders().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new and/or updated header and value.

Parameters
name
Case-insensitive header field name.
value
Header value(s).
Return Value
static
phpDoc
throws: for invalid header names or values. InvalidArgumentException
withoutHeader(string $name): static

Return an instance without the specified header.

modifiers
abstract
Description

Header resolution MUST be done without case-sensitivity.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the named header.

Parameters
name
Case-insensitive header field name to remove.
Return Value
static
withProtocolVersion(string $version): static

Return an instance with the specified HTTP protocol version.

modifiers
abstract
Description

The version string MUST contain only the HTTP version number (e.g., "1.1", "1.0").

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new protocol version.

Parameters
version
HTTP protocol version
Return Value
static

bdk\HttpMessage\Stream

Describes a data stream.

Implements

  • Psr\Http\Message\StreamInterface
    • Stringable

Methods

__construct(mixed $resource = null[, array $options = array()])

This constructor accepts an associative array of options.

Description
  • metadata: (array) Any additional metadata to return when the metadata of the stream is accessed.
  • size: (int) If a read stream would otherwise have an indeterminate size, but the size is known due to foreknowledge, then you can provide that size, in bytes.
Parameters
resource
Resource, file, or string content to wrap.
options
Associative array of options.
phpDoc
throws: if the stream is not a stream resource InvalidArgumentException
__toString(): string

Reads all data from the stream into a string, from the beginning to end.

Description

Warning: This could attempt to load a large amount of data into memory.

Return Value
string
phpDoc
see: http://php.net/manual/en/language.oop5.magic.php#object.tostring
close()

Closes the stream and any underlying resources.

detach(): resource|null

Separates any underlying resources from the stream.

Description

After the stream has been detached, the stream is in an unusable state.

Return Value
resource|null
Underlying PHP stream, if any
eof(): bool

Returns true if the stream is at the end of the stream.

Return Value
bool
phpDoc
throws: RuntimeException
getContents(): string

Returns the remaining contents in a string

Return Value
string
phpDoc
throws: if unable to read or an error occurs while reading. RuntimeException
getMetadata(string|null $key = null): array|mixed|null

Get stream metadata as an associative array or retrieve a specific key.

Description

The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.

Parameters
key
Specific metadata to retrieve.
Return Value
array|mixed|null
Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found.
phpDoc
psalm-suppress: PossiblyInvalidArgument we know resource is open
getSize(): int|null

Get the size of the stream if known.

Return Value
int|null
Returns the size in bytes if known, or null if unknown.
isReadable(): bool

Returns whether or not the stream is readable.

Return Value
bool
isSeekable(): bool

Returns whether or not the stream is seekable.

Return Value
bool
isWritable(): bool

Returns whether or not the stream is writable.

Return Value
bool
read(int $length): string

Read data from the stream.

Parameters
length
Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.
Return Value
string
Returns the data read from the stream, or an empty string if no bytes are available.
phpDoc
throws: if an error occurs. RuntimeException
throws: if negative length specified InvalidArgumentException
rewind()

Seek to the beginning of the stream.

Description

If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).

phpDoc
see: seek()
throws: on failure. RuntimeException
seek(int $offset[, int $whence = SEEK_SET])

Seek to a position in the stream.

Parameters
offset
Stream offset
whence
Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for fseek(). SEEK_SET: Set position equal to offset bytes SEEK_CUR: Set position to current location plus offset SEEK_END: Set position to end-of-stream plus offset.
phpDoc
throws: on failure. RuntimeException
tell(): int

Returns the current position of the file read/write pointer

Return Value
int
Position of the file pointer
phpDoc
throws: on error. RuntimeException
write(string $string): int

Write data to the stream.

Parameters
string
The string that is to be written.
Return Value
int
Returns the number of bytes written to the stream.
phpDoc
throws: on failure. RuntimeException

bdk\HttpMessage\UploadedFile

Value object representing a file uploaded through an HTTP request.

Instances of this interface are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current instance and return an instance that contains the changed state.

Implements

    Psr\Http\Message\UploadedFileInterface

Methods

__construct(mixed …$values = array())

Constructor

Description

construct(array $fileInfo) construct($streamOrFile, $size = null, $error = UPLOAD_ERR_OK, $clientFilename = null, $clientMediaType = null, $clientFullPath = null)

Parameters
values
Uploaded file values as populated in $_FILES array null|string|resource|StreamInterface tmp_name filepath, resource, or StreamInterface int size Size in bytes int error one of the UPLOADERR* constants string name client file name string type client mime type string full_path client full path (as of php 8.1)
phpDoc
see: https://www.php.net/manual/en/features.file-upload.post-method.php
throws: InvalidArgumentException
getClientFilename(): string|null

Retrieve the filename sent by the client.

Description

Do not trust the value returned by this method. A client could send a malicious filename with the intention to corrupt or hack your application.

Return Value
string|null
The filename sent by the client or null if none was provided.
getClientFullPath(): string|null

Retrieve the full_path sent by the client.

Description

full_path value is new as of PHP 8.1 and passed by client when uploading a directory

Do not trust the value returned by this method. A client could send a malicious filename with the intention to corrupt or hack your application.

Note: This method is not part of the PSR-7 standard.
Return Value
string|null
The full-path sent by the client or null if none was provided.
getClientMediaType(): string|null

Retrieve the media type sent by the client.

Description

Do not trust the value returned by this method. A client could send a malicious media type with the intention to corrupt or hack your application.

Return Value
string|null
The media type sent by the client or null if none was provided.
getError(): int

Retrieve the error associated with the uploaded file.

Description

Returns one of PHP's UPLOAD_ERR_XXX constants.

If the file was uploaded successfully, will return UPLOAD_ERR_OK.

Return Value
int
One of PHP's UPLOAD_ERR_XXX constants.
phpDoc
see: http://php.net/manual/en/features.file-upload.errors.php
getErrorMessage(): string

Get uploaded file's error message

Description

If the file was uploaded successfully, will return ''

Note: This method is not part of the PSR-7 standard.
Return Value
string
getSize(): int|null

Retrieve the file size.

Description

Implementations SHOULD return the value stored in the "size" key of the file in the $_FILES array if available, as PHP calculates this based on the actual size transmitted.

Return Value
int|null
The file size in bytes or null if unknown.
getStream(): Psr\Http\Message\StreamInterface

Retrieve a stream representing the uploaded file.

Description

If the moveTo() method has been called previously, this method will raise an exception.

Return Value
Psr\Http\Message\StreamInterface
representation of the uploaded file.
phpDoc
throws: in cases when no stream is available or can be created. RuntimeException
moveTo(string $targetPath)

Move the uploaded file to a new location.

Description

Use this method as an alternative to move_uploaded_file(). This method is guaranteed to work in both SAPI and non-SAPI environments.

$targetPath may be an absolute path, or a relative path. If it is a relative path, resolution will be the same as used by PHP's rename() function.

The original file or stream will be removed on completion.

If this method is called more than once, any subsequent calls will raise an exception.

When used in an SAPI environment where $_FILES is populated, when writing files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be used to ensure permissions and upload status are verified correctly.

If you wish to move to a stream, use getStream(), as SAPI operations cannot guarantee writing to stream destinations.

Parameters
targetPath
Path to which to move the uploaded file.
phpDoc
see: http://php.net/is_uploaded_file
see: http://php.net/move_uploaded_file
throws: if the $targetPath specified is invalid. InvalidArgumentException
throws: on any error during the move operation, or on the second or subsequent call to the method. RuntimeException

bdk\HttpMessage\Uri

Value object representing a URI.

Represent a URI according to RFC 3986 and provide methods for most common operations.

Instances of this interface are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current instance and return an instance that contains the changed state.

Implements

  • Psr\Http\Message\UriInterface
    • Stringable

Methods

__construct(string|null $uri = null)

Constructor

Parameters
uri
Uri to wrap
phpDoc
throws: InvalidArgumentException
__toString(): string

Return stringified value

Return Value
string
static fromGlobals(): bdk\HttpMessage\Uri

Get a Uri populated with values from $_SERVER.

Return Value
bdk\HttpMessage\Uri
getAuthority(): string

Retrieve the authority component of the URI.

Description

If the port component is not set or is the standard port for the current scheme, it will not be included

Return Value
string
The URI authority, in "[user-info@]host[:port]" format. (or empty string)
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2
getFragment(): string

Retrieve the fragment component of the URI.

Description

The leading "#" character is not part of the fragment and MUST NOT be added.

The value returned will be percent-encoded, but will not double-encode any characters. see RFC 3986, Sections 2 and 3.5.

Return Value
string
The URI fragment. (or empty string)
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-2
see: https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
getHost(): string

Retrieve the host component of the URI.

Description

The value returned will be normalized to lowercase, per RFC 3986 Section 3.2.2.

Return Value
string
The URI host (or empty string).
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
getPath(): string

Retrieve the path component of the URI.

Description

The path can either be empty or absolute (starting with a slash) rootless (not starting with a slash).

Normally, the empty path "" and absolute path "/" are considered equal as defined in RFC 7230 Section 2.7.3. But this method does automatically do this normalization because in contexts with a trimmed base path, e.g. the front controller, this difference becomes significant. It's the task of the user to handle both "" and "/".

The value returned will be percent-encoded, but will not double-encode any characters. see RFC 3986, Sections 2 and 3.3.

As an example, if the value should include a slash ("/") not intended as delimiter between path segments, that value will be passed in encoded form (e.g., "%2F") to the instance.

Return Value
string
The URI path.
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-2
see: https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
getPort(): null|int

Retrieve the port component of the URI.

Description

If the port is the standard port used with the current scheme, null will be returned.

If no port is present, and no scheme is present, null will be returned

If no port is present, but a scheme is present, null will be returned.

Return Value
null|int
The URI port.
getQuery(): string

Retrieve the query string of the URI.

Description

The leading "?" character is not part of the query and will not be included.

The value returned will be percent-encoded, but will not double-encode any characters. see RFC 3986, Sections 2 and 3.4.

As an example, if a value in a key/value pair of the query string should include an ampersand ("&") not intended as a delimiter between values, that value MUST be passed in encoded form (e.g., "%26") to the instance.

Return Value
string
The URI query string. (or empty string)
phpDoc
see: https://datatracker.ietf.org/doc/html/rfc3986#section-2
see: https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
getScheme(): string

Retrieve the scheme component of the URI.

Return Value
string
getUserInfo(): string

Retrieve the user information component of the URI.

Description

If a user is present in the URI, this will return that value; additionally, if the password is also present, it will be appended to the user value, with a colon (":") separating the values.

The trailing "@" character is not part of the user information and will not be included

Return Value
string
The URI user information, in "username[:password]" format. (or empty string)
withFragment(string $fragment): static

Return an instance with the specified URI fragment.

Description

Users can provide both encoded and decoded fragment characters.

An empty fragment value is equivalent to removing the fragment.

Parameters
fragment
The fragment to use with the new instance.
Return Value
static
A new instance with the specified fragment.
withHost(string $host): static

Return an instance with the specified host.

Description

An empty host value is equivalent to removing the host.

Parameters
host
The hostname to use with the new instance.
Return Value
static
A new instance with the specified host.
phpDoc
throws: for invalid hostnames. InvalidArgumentException
withPath(string $path): static

Return an instance with the specified path.

Description

The path can either be empty absolute (starting with a slash) rootless (not starting with a slash).

If an HTTP path is intended to be host-relative rather than path-relative then it must begin with a slash ("/"). HTTP paths not starting with a slash are assumed to be relative to some base path known to the application or consumer.

Users can provide both encoded and decoded path characters.

Parameters
path
The path to use with the new instance.
Return Value
static
A new instance with the specified path.
phpDoc
throws: for invalid paths. InvalidArgumentException
withPort(null|int $port): static

Return an instance with the specified port.

Description

A null value provided for the port is equivalent to removing the port information.

Parameters
port
The port to use with the new instance; a null value removes the port information.
Return Value
static
A new instance with the specified port.
phpDoc
throws: for invalid ports. InvalidArgumentException
withQuery(string $query): static

Return an instance with the specified query string.

Description

Users can provide both encoded and decoded query characters.

An empty query string value is equivalent to removing the query string.

Parameters
query
The query string to use with the new instance.
Return Value
static
A new instance with the specified query string.
phpDoc
throws: for invalid query strings. InvalidArgumentException
withScheme(string $scheme): static

Return an instance with the specified scheme.

Description

An empty scheme is equivalent to removing the scheme.

Parameters
scheme
The scheme to use with the new instance.
Return Value
static
A new instance with the specified scheme.
phpDoc
throws: for invalid / unsupported schemes. InvalidArgumentException
withUserInfo(string $user[, null|string $password = null]): static

Return an instance with the specified user information.

Description

Password is optional, but the user information MUST include the user; an empty string for the user is equivalent to removing user information.

Parameters
user
The user name to use for authority.
password
The password associated with $user.
Return Value
static
A new instance with the specified user information.

bdk\HttpMessage\Utility\ContentType

Define common mime types

Constants

public CSS = text/css
public CSV = text/csv
public FONT_TTF = font/ttf
public FONT_WOFF = font/woff
public FONT_WOFF2 = font/woff2
public FORM = application/x-www-form-urlencoded
public FORM_MULTIPART = multipart/form-data
public GZ = application/gzip
public HTML = text/html
public IMAGE_GIF = image/gif
public IMAGE_ICO = image/vnd.microsoft.icon
public IMAGE_JPEG = image/jpeg
public IMAGE_PNG = image/png
public IMAGE_SVG = image/svg+xml
public JS = text/javascript
public JSON = application/json
public MARKDOWN = text/markdown
public PDF = application/pdf
public SQL = application/sql
public TXT = text/plain
public XML = text/xml
public XML_APP = application/xml
public ZIP = application/zip

bdk\HttpMessage\Utility\HttpFoundationBridge

Factories for creating ServerRequest & Response from HttpFoundation objects

Methods

static createRequest(Symfony\Component\HttpFoundation\Request $request): bdk\HttpMessage\ServerRequestExtended

Create a Psr7 request object from HttpFoundation request

Parameters
request
HttpFoundation\Request obj
Return Value
bdk\HttpMessage\ServerRequestExtended
phpDoc
psalm-suppress: ReservedWord complains about HttpFoundations' : mixed return spec
static createResponse(Symfony\Component\HttpFoundation\Response $response): bdk\HttpMessage\Response

Create Response from HttpFoundationResponse

Parameters
response
HttpFoundationResponse instance
Return Value
bdk\HttpMessage\Response

bdk\HttpMessage\Utility\ParseStr

PHP's parse_str(), but does not convert dots and spaces to '_' by default

PHP's maintains a side-effect of the long-removed register_globals directive that affects $_POST and $_GET Spaces and '.'s are converted to '_' for top level keys.

$input = 'foo_bar=baz+1&foo+bar=baz+2&foo%2Bbar=baz+3&foo.bar=baz+4';
parse_str($input, $vals);
var_dump($vals);

$vals = \bdk\HttpMessage\Utility\ParseStr::parse($input);
var_dump($vals);

Output:

array(
   'foo_bar' =&gt; 'baz 4',
   'foo+bar' =&gt; 'baz 3',
)
array(
   'foo_bar' =&gt; 'baz 1',
   'foo bar' =&gt; 'baz 2',
   'foo+bar' =&gt; 'baz 3',
   'foo.bar' =&gt; 'baz 4',
)

Methods

static parse(string|null $str[, array $opts = array()]): array

like PHP's parse_str()

Description

Key difference: by default this does not convert root key dots and spaces to '_'

Parameters
str
input string
opts
parse options (default: {convDot:false, convSpace:false})
Return Value
array
phpDoc
see: https://github.com/api-platform/core/blob/main/src/Core/Util/RequestParser.php#L50
static setOpts(array|string $mixed[, mixed $val = null])

Set default parseStr option(s)

Description
parseStrOpts('convDot', true)
parseStrOpts(array('convDot' =&gt; true, 'convSpace' =&gt; true))
Parameters
mixed
key=>value array or key
val
new value
phpDoc
throws: InvalidArgumentException

bdk\HttpMessage\Utility\Response

Response Utilities

Methods

static codePhrase(int|string $code): string

Get the standard "phrase" associated with the status code

Parameters
code
3-digit status code
Return Value
string
empty string if unknown code
static emit(Psr\Http\Message\ResponseInterface $response)

Output response headers and body

Parameters
response
Response instance
phpDoc
phpcs: :disable SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified

bdk\HttpMessage\Utility\ServerRequest

Build ServerRequest from globals ($_SERVER, $_COOKIE, $_POST, $_FILES)

Methods

static fromGlobals(array $parseStrOpts = array()): bdk\HttpMessage\ServerRequestExtended

Instantiate ServerRequest instance from superglobals

Parameters
parseStrOpts
Parse options (default: {convDot:false, convSpace:false})
Return Value
bdk\HttpMessage\ServerRequestExtended
phpDoc
SuppressWarnings: (PHPMD.Superglobals)

bdk\HttpMessage\Utility\Stream

Stream Utilities

Methods

static getContents(Psr\Http\Message\StreamInterface $stream): string

Get stream contents without affecting pointer

Parameters
stream
StreamInterface
Return Value
string

bdk\HttpMessage\Utility\Uri

Uri Utilities

Methods

static fromGlobals(): bdk\HttpMessage\Uri

Get a Uri populated with values from $_SERVER.

Return Value
bdk\HttpMessage\Uri
phpDoc
SuppressWarnings: (PHPMD.Superglobals)
static fromParsed(array $parsed): bdk\HttpMessage\Uri

Get a Uri populated with component values

Description

Username & password accepted in multiple ways (highest precedence first):

  • userInfo ("username:password" or ["username", "password"])
  • user & pass
  • username & password
Parameters
parsed
Url component values (ie from parse_url())
Return Value
bdk\HttpMessage\Uri
phpDoc
since: x.3.2
static isCrossOrigin(Psr\Http\Message\UriInterface $uri1, Psr\Http\Message\UriInterface $uri2): bool

Determines if two Uri's should be considered cross-origin

Parameters
uri1
Uri 1
uri2
Uri 2
Return Value
bool
static parseUrl(string|Psr\Http\Message\UriInterface $url): array<string,int|string>|false

Parse URL (multi-byte safe)

Parameters
url
The URL to parse.
Return Value
array<string,int|string>|false
static resolve(Psr\Http\Message\UriInterface $base, Psr\Http\Message\UriInterface $rel): Psr\Http\Message\UriInterface

Converts the relative URI into a new URI that is resolved against the base URI.

Parameters
base
Base URI
rel
Relative URI
Return Value
Psr\Http\Message\UriInterface
phpDoc