Documentation

AbstractRequestResponse
in package
implements RequestResponseInterface, MessageInterface

AbstractYes

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
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

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

$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 = []

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

decodeBodyContent()

Decode the body

public decodeBodyContent([string|null $body = null ]) : Body
Parameters
$body : string|null = null
Return values
Body

getBody()

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
Body

getBodyContentLength()

Get body content length

public getBodyContentLength([bool $mb = false ]) : int
Parameters
$mb : bool = false
Return values
int

getHeader()

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
string

getHeaderObject()

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
string

getHeaderValue()

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|null

hasHeader()

Has a header

public hasHeader(string $name) : bool
Parameters
$name : string
Return values
bool

withAddedHeader()

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
static

withBody()

Return an instance with the specified body, per PSR-7

public withBody(Body|StreamInterface $body) : static
Parameters
$body : Body|StreamInterface
Return values
static

withHeader()

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
static

withoutHeader()

Return an instance without the specified header, per PSR-7

public withoutHeader(string $name) : static
Parameters
$name : string
Return values
static

resolveHeaderName()

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
Return values
string

        
On this page

Search results