Skip to content

MessageDecoratorTrait

This trait contains a bunch of methods, shared by both the RequestDecorator and the ResponseDecorator.

Didn't seem needed to create a full class for this, so we're just implementing it as a trait.

  • Full name: \Sabre\HTTP\MessageDecoratorTrait

Properties

inner

The inner request object.

protected \Sabre\HTTP\MessageInterface $inner

All method calls will be forwarded here.


Methods

getBodyAsStream

Returns the body as a readable stream resource.

public getBodyAsStream(): resource

Note that the stream may not be rewindable, and therefore may only be read once.


getBodyAsString

Returns the body as a string.

public getBodyAsString(): string

Note that because the underlying data may be based on a stream, this method could only work correctly the first time.


getBody

Returns the message body, as its internal representation.

public getBody(): resource|string

This could be either a string or a stream.


setBody

Updates the body resource with a new stream.

public setBody(resource|string|callable $body): mixed

Parameters:

Parameter Type Description
$body resource|string|callable

getHeaders

Returns all the HTTP headers as an array.

public getHeaders(): array

Every header is returned as an array, with one or more values.


hasHeader

Will return true or false, depending on if a HTTP header exists.

public hasHeader(string $name): bool

Parameters:

Parameter Type Description
$name string

getHeader

Returns a specific HTTP header, based on its name.

public getHeader(string $name): string|null

The name must be treated as case-insensitive. If the header does not exist, this method must return null.

If a header appeared more than once in a HTTP request, this method will concatenate all the values with a comma.

Note that this not make sense for all headers. Some, such as Set-Cookie cannot be logically combined with a comma. In those cases you should use getHeaderAsArray().

Parameters:

Parameter Type Description
$name string

getHeaderAsArray

Returns a HTTP header as an array.

public getHeaderAsArray(string $name): array

For every time the HTTP header appeared in the request or response, an item will appear in the array.

If the header did not exist, this method will return an empty array.

Parameters:

Parameter Type Description
$name string

setHeader

Updates a HTTP header.

public setHeader(string $name, string|string[] $value): mixed

The case-sensitivity of the name value must be retained as-is.

If the header already existed, it will be overwritten.

Parameters:

Parameter Type Description
$name string
$value string|string[]

setHeaders

Sets a new set of HTTP headers.

public setHeaders(array $headers): mixed

The headers array should contain headernames for keys, and their value should be specified as either a string or an array.

Any header that already existed will be overwritten.

Parameters:

Parameter Type Description
$headers array

addHeader

Adds a HTTP header.

public addHeader(string $name, string|string[] $value): mixed

This method will not overwrite any existing HTTP header, but instead add another value. Individual values can be retrieved with getHeadersAsArray.

Parameters:

Parameter Type Description
$name string
$value string|string[]

addHeaders

Adds a new set of HTTP headers.

public addHeaders(array $headers): mixed

Any existing headers will not be overwritten.

Parameters:

Parameter Type Description
$headers array

removeHeader

Removes a HTTP header.

public removeHeader(string $name): bool

The specified header name must be treated as case-insensitive. This method should return true if the header was successfully deleted, and false if the header did not exist.

Parameters:

Parameter Type Description
$name string

setHttpVersion

Sets the HTTP version.

public setHttpVersion(string $version): mixed

Should be 1.0, 1.1 or 2.0.

Parameters:

Parameter Type Description
$version string

getHttpVersion

Returns the HTTP version.

public getHttpVersion(): string


Automatically generated on 2025-03-18