Trait MessageTrait
Implements the methods defined in Psr\Http\Message\MessageInterface.
Property Summary
-
$headerNames protected
array<non-empty-string, non-empty-string>Map of lowercased header name to the original name used to register the header.
-
$headers protected
array<non-empty-string, non-empty-list<string>>List of all registered headers, as original name => list of values.
-
$protocol protected
stringThe HTTP protocol version.
-
$stream protected
Psr\Http\Message\StreamInterfaceThe message body.
Method Summary
-
assertHeaderName() protected
Validate a header name.
-
assertStatus() protected
Validate status line components before they reach an emitter.
-
filterHeaderValue() protected
Validate and normalize header values.
-
getBody() public
Gets the body of the message.
-
getHeader() public
Retrieves a message header value by the given case-insensitive name.
-
getHeaderLine() public
Retrieves a comma-separated string of the values for a single header.
-
getHeaders() public
Retrieves all message headers.
-
getProtocolVersion() public
Retrieves the HTTP protocol version as a string.
-
hasHeader() public
Checks if a header exists by the given case-insensitive name.
-
removeHeader() protected
Remove a header from the current instance.
-
replaceHeader() protected
Replace a header on the current instance.
-
withAddedHeader() public
Return an instance with the specified header appended with the given value.
-
withBody() public
Return an instance with the specified message body.
-
withHeader() public
Return an instance with the provided header, replacing any existing values of any headers with the same case-insensitive name.
-
withProtocolVersion() public
Return an instance with the specified HTTP protocol version.
-
withoutHeader() public
Return an instance without the specified header.
Method Detail
assertHeaderName() ¶ protected
assertHeaderName(string $name): void
Validate a header name.
Parameters
-
string$name The header name.
Returns
voidThrows
InvalidArgumentExceptionWhen the name isn't a valid RFC 7230 token.
assertStatus() ¶ protected
assertStatus(int $code, string $reasonPhrase): void
Validate status line components before they reach an emitter.
Parameters
-
int$code HTTP status code.
-
string$reasonPhrase Optional reason phrase.
Returns
voidfilterHeaderValue() ¶ protected
filterHeaderValue(mixed $values): non-empty-list<string>
Validate and normalize header values.
Parameters
-
mixed$values A header value or list of header values.
Returns
non-empty-list<string>Throws
InvalidArgumentExceptionWhen a value is invalid.
getBody() ¶ public
getBody(): Psr\Http\Message\StreamInterface
Gets the body of the message.
Returns
Psr\Http\Message\StreamInterfacegetHeader() ¶ public
getHeader(string $name): list<string>
Retrieves a message header value by the given case-insensitive name.
Parameters
-
string$name Case-insensitive header name.
Returns
list<string>The header values, or an empty array if the header is not set.
getHeaderLine() ¶ public
getHeaderLine(string $name): string
Retrieves a comma-separated string of the values for a single header.
Parameters
-
string$name Case-insensitive header name.
Returns
stringThe header values joined by a comma, or an empty string if the header is not set.
getHeaders() ¶ public
getHeaders(): array<non-empty-string, non-empty-list<string>>
Retrieves all message headers.
Returns
array<non-empty-string, non-empty-list<string>>Header names mapped to their list of values.
getProtocolVersion() ¶ public
getProtocolVersion(): string
Retrieves the HTTP protocol version as a string.
Returns
stringHTTP protocol version.
hasHeader() ¶ public
hasHeader(string $name): bool
Checks if a header exists by the given case-insensitive name.
Parameters
-
string$name Case-insensitive header name.
Returns
boolremoveHeader() ¶ protected
removeHeader(string $name): void
Remove a header from the current instance.
Parameters
-
string$name Case-insensitive header name.
Returns
voidreplaceHeader() ¶ protected
replaceHeader(non-empty-string $name, non-empty-list<string> $value): void
Replace a header on the current instance.
Parameters
-
non-empty-string$name The header name.
-
non-empty-list<string>$value The filtered header values.
Returns
voidwithAddedHeader() ¶ public
withAddedHeader(string $name, array<string>|string $value): static
Return an instance with the specified header appended with the given value.
Parameters
-
string$name Case-insensitive header name.
-
array<string>|string$value Header value(s).
Returns
staticThrows
InvalidArgumentExceptionFor invalid header names or values.
withBody() ¶ public
withBody(Psr\Http\Message\StreamInterface $body): static
Return an instance with the specified message body.
Parameters
-
Psr\Http\Message\StreamInterface$body The new body.
Returns
staticwithHeader() ¶ public
withHeader(string $name, array<string>|string $value): static
Return an instance with the provided header, replacing any existing values of any headers with the same case-insensitive name.
Parameters
-
string$name Case-insensitive header name.
-
array<string>|string$value Header value(s).
Returns
staticThrows
InvalidArgumentExceptionFor invalid header names or values.
withProtocolVersion() ¶ public
withProtocolVersion(string $version): static
Return an instance with the specified HTTP protocol version.
Parameters
-
string$version HTTP protocol version.
Returns
staticThrows
InvalidArgumentExceptionFor unsupported protocol versions.
withoutHeader() ¶ public
withoutHeader(string $name): static
Return an instance without the specified header.
Parameters
-
string$name Case-insensitive header name.
Returns
staticProperty Detail
$headerNames ¶ protected
Map of lowercased header name to the original name used to register the header.
Type
array<non-empty-string, non-empty-string>$headers ¶ protected
List of all registered headers, as original name => list of values.
Type
array<non-empty-string, non-empty-list<string>>