AbstractRequestResponse
in package
implements
RequestResponseInterface, MessageInterface
Abstract HTTP request/response class
Declares implements MessageInterface here (in addition to the concrete
implements RequestInterface/ResponseInterface added to AbstractRequest/
AbstractResponse) because PHP's covariant-return check for static requires
the class where a method is physically defined to already be provably
compatible with the interface's return type; without this, PHP fatals on
withHeader()/withAddedHeader()/withoutHeader()/withBody() as soon as
a subclass implements MessageInterface, even though those methods'
behavior already satisfies it. getProtocolVersion()/withProtocolVersion()
remain unimplemented here (legal since this class stays abstract) — added by
AbstractRequest/AbstractResponse per PSR-7 message methods task.
Tags
Table of Contents
Interfaces
- RequestResponseInterface
- HTTP request/response interface
- MessageInterface
Properties
- $body : Body|null
- Body
- $headerIndex : array<string|int, mixed>
- Case-folded header name index (lowercase name => actual stored key), kept in sync by addHeader()/removeHeader()/setHeaders()/removeHeaders() so resolveHeaderName() - used by every PSR-7 case-insensitive lookup (getHeader()/withHeader()/withAddedHeader()/ withoutHeader()) - is an O(1) lookup instead of a linear strcasecmp() scan of every header.
- $headers : array<string|int, mixed>
- Headers
Methods
- __clone() : void
- Deep-clone headers and body so a with*() clone never shares mutable state with the instance it was cloned from
- __get() : mixed
- Magic method to get either the headers or body
- addHeader() : AbstractRequestResponse
- Add a header
- addHeaders() : AbstractRequestResponse
- Add all headers
- decodeBodyContent() : Body
- Decode the body
- getBody() : Body
- Get the body, per PSR-7 (a transient, never-stored empty Body when none is set, so hasBody() remains unaffected by calling this)
- getBodyContent() : mixed
- Get body content
- getBodyContentLength() : int
- Get body content length
- getHeader() : array<string|int, mixed>
- Get all string values for a header, per PSR-7 (empty array if absent, case-insensitive)
- getHeaderAsString() : mixed
- Get a header
- getHeaderLine() : string
- Get a header's values comma-joined into one string, per PSR-7
- getHeaderObject() : mixed
- Get a header
- getHeaderObjects() : array<string|int, mixed>
- Get all headers
- getHeaders() : array<string|int, mixed>
- Get all headers, per PSR-7 (each header's values array-wrapped)
- getHeadersAsArray() : array<string|int, mixed>
- Get all header values as associative array
- getHeadersAsString() : string
- Get all header values formatted string
- getHeaderValue() : mixed
- Get header value
- getHeaderValueAsString() : string|null
- Get header value as string
- hasBody() : bool
- Has a body
- hasBodyContent() : bool
- Has body content
- hasHeader() : bool
- Has a header
- hasHeaders() : bool
- Determine if there are headers
- removeBody() : AbstractRequestResponse
- Remove the body
- removeHeader() : AbstractRequestResponse
- Remove a header
- removeHeaders() : AbstractRequestResponse
- Remove all headers
- setBody() : AbstractRequestResponse
- Set the body
- setHeaders() : AbstractRequestResponse
- Set all headers (clear out any existing headers)
- withAddedHeader() : static
- Return an instance with the specified header value(s) appended, per PSR-7
- withBody() : static
- Return an instance with the specified body, per PSR-7
- withHeader() : static
- Return an instance with the specified header, replacing any existing values, per PSR-7
- withoutHeader() : static
- Return an instance without the specified header, per PSR-7
- resolveHeaderName() : string
- Resolve a header name to whatever key is actually stored, matching case-insensitively per PSR-7. Returns the input unchanged if no existing header matches. Only PSR-7-facing methods route through this - the non-PSR addHeader()/removeHeader()/hasHeader()/ getHeaderObject()/getHeaderObjects() methods keep their existing exact-match storage keying.
Properties
$body
Body
protected
Body|null
$body
= null
$headerIndex
Case-folded header name index (lowercase name => actual stored key), kept in sync by addHeader()/removeHeader()/setHeaders()/removeHeaders() so resolveHeaderName() - used by every PSR-7 case-insensitive lookup (getHeader()/withHeader()/withAddedHeader()/ withoutHeader()) - is an O(1) lookup instead of a linear strcasecmp() scan of every header.
protected
array<string|int, mixed>
$headerIndex
= []
$headers
Headers
protected
array<string|int, mixed>
$headers
= []
Methods
__clone()
Deep-clone headers and body so a with*() clone never shares mutable state with the instance it was cloned from
public
__clone() : void
__get()
Magic method to get either the headers or body
public
__get(string $name) : mixed
Parameters
- $name : string
addHeader()
Add a header
public
addHeader(Header|string|int $header[, string|null $value = null ]) : AbstractRequestResponse
Parameters
- $header : Header|string|int
- $value : string|null = null
Return values
AbstractRequestResponseaddHeaders()
Add all headers
public
addHeaders(array<string|int, mixed> $headers) : AbstractRequestResponse
Parameters
- $headers : array<string|int, mixed>
Return values
AbstractRequestResponsedecodeBodyContent()
Decode the body
public
decodeBodyContent([string|null $body = null ]) : Body
Parameters
- $body : string|null = null
Return values
BodygetBody()
Get the body, per PSR-7 (a transient, never-stored empty Body when none is set, so hasBody() remains unaffected by calling this)
public
getBody() : Body
Return values
BodygetBodyContent()
Get body content
public
getBodyContent() : mixed
getBodyContentLength()
Get body content length
public
getBodyContentLength([bool $mb = false ]) : int
Parameters
- $mb : bool = false
Return values
intgetHeader()
Get all string values for a header, per PSR-7 (empty array if absent, case-insensitive)
public
getHeader(string $name) : array<string|int, mixed>
Parameters
- $name : string
Return values
array<string|int, mixed>getHeaderAsString()
Get a header
public
getHeaderAsString(string $name) : mixed
Parameters
- $name : string
getHeaderLine()
Get a header's values comma-joined into one string, per PSR-7
public
getHeaderLine(string $name) : string
Parameters
- $name : string
Return values
stringgetHeaderObject()
Get a header
public
getHeaderObject(string $name) : mixed
Parameters
- $name : string
getHeaderObjects()
Get all headers
public
getHeaderObjects() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeaders()
Get all headers, per PSR-7 (each header's values array-wrapped)
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeadersAsArray()
Get all header values as associative array
public
getHeadersAsArray([bool $asStrings = true ]) : array<string|int, mixed>
Parameters
- $asStrings : bool = true
Return values
array<string|int, mixed>getHeadersAsString()
Get all header values formatted string
public
getHeadersAsString([mixed $status = null ][, string $eol = "
" ]) : string
Parameters
- $status : mixed = null
- $eol : string = " "
Return values
stringgetHeaderValue()
Get header value
public
getHeaderValue(string $name[, int $i = 0 ]) : mixed
Parameters
- $name : string
- $i : int = 0
getHeaderValueAsString()
Get header value as string
public
getHeaderValueAsString(string $name[, int $i = 0 ]) : string|null
Parameters
- $name : string
- $i : int = 0
Return values
string|nullhasBody()
Has a body
public
hasBody() : bool
Return values
boolhasBodyContent()
Has body content
public
hasBodyContent() : bool
Return values
boolhasHeader()
Has a header
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
boolhasHeaders()
Determine if there are headers
public
hasHeaders() : bool
Return values
boolremoveBody()
Remove the body
public
removeBody() : AbstractRequestResponse
Return values
AbstractRequestResponseremoveHeader()
Remove a header
public
removeHeader(string $name) : AbstractRequestResponse
Parameters
- $name : string
Return values
AbstractRequestResponseremoveHeaders()
Remove all headers
public
removeHeaders() : AbstractRequestResponse
Return values
AbstractRequestResponsesetBody()
Set the body
public
setBody(string|Body $body) : AbstractRequestResponse
Parameters
- $body : string|Body
Return values
AbstractRequestResponsesetHeaders()
Set all headers (clear out any existing headers)
public
setHeaders(array<string|int, mixed> $headers) : AbstractRequestResponse
Parameters
- $headers : array<string|int, mixed>
Return values
AbstractRequestResponsewithAddedHeader()
Return an instance with the specified header value(s) appended, per PSR-7
public
withAddedHeader(string $name, mixed $value) : static
Parameter is typed mixed (rather than string|array) only to satisfy PSR-7's
untyped MessageInterface::withAddedHeader() signature per PHP's LSP variance
rules; the supported values remain a string or an array of strings.
Parameters
- $name : string
- $value : mixed
Return values
staticwithBody()
Return an instance with the specified body, per PSR-7
public
withBody(Body|StreamInterface $body) : static
Parameters
- $body : Body|StreamInterface
Return values
staticwithHeader()
Return an instance with the specified header, replacing any existing values, per PSR-7
public
withHeader(string $name, mixed $value) : static
Parameter is typed mixed (rather than string|array) only to satisfy PSR-7's
untyped MessageInterface::withHeader() signature per PHP's LSP variance rules;
the supported values remain a string or an array of strings.
Parameters
- $name : string
- $value : mixed
Return values
staticwithoutHeader()
Return an instance without the specified header, per PSR-7
public
withoutHeader(string $name) : static
Parameters
- $name : string
Return values
staticresolveHeaderName()
Resolve a header name to whatever key is actually stored, matching case-insensitively per PSR-7. Returns the input unchanged if no existing header matches. Only PSR-7-facing methods route through this - the non-PSR addHeader()/removeHeader()/hasHeader()/ getHeaderObject()/getHeaderObjects() methods keep their existing exact-match storage keying.
private
resolveHeaderName(string $name) : string
Parameters
- $name : string