Documentation

AbstractRequest extends AbstractRequestResponse
in package
implements RequestInterface

AbstractYes

Abstract HTTP request class

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

RequestInterface

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
$protocolVersion  : string
HTTP protocol version, per PSR-7
$requestTargetOverride  : string|null
Explicit request-target override, per PSR-7 (null = derive from the URI)
$uri  : Uri|null
Request URI object

Methods

__clone()  : void
Deep-clone the URI so a with*() clone never shares a mutable Uri instance with the instance it was cloned from
__construct()  : mixed
Constructor
__get()  : mixed
Magic method to get either the headers or body
addHeader()  : AbstractRequestResponse
Add a header
addHeaders()  : AbstractRequestResponse
Add all headers
clearUri()  : AbstractRequest
Clear URI
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
getProtocolVersion()  : string
Get the HTTP protocol version, per PSR-7
getRequestTarget()  : string
Get the request target, per PSR-7 (path + query, or '/' with no URI, unless overridden)
getUri()  : Uri
Get URI, per PSR-7 (a transient, never-stored empty Uri when none is set, so hasUri() remains unaffected by calling this)
getUriAsString()  : string
Get URI as string
hasBody()  : bool
Has a body
hasBodyContent()  : bool
Has body content
hasHeader()  : bool
Has a header
hasHeaders()  : bool
Determine if there are headers
hasUri()  : bool
Has URI
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)
setUri()  : AbstractRequest
Set URI
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
withProtocolVersion()  : static
Return an instance with the specified HTTP protocol version, per PSR-7
withRequestTarget()  : static
Return an instance with the specified request target, per PSR-7
withUri()  : static
Return an instance with the specified URI, per PSR-7

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

$protocolVersion

HTTP protocol version, per PSR-7

protected string $protocolVersion = '1.1'

$requestTargetOverride

Explicit request-target override, per PSR-7 (null = derive from the URI)

protected string|null $requestTargetOverride = null

Methods

__clone()

Deep-clone the URI so a with*() clone never shares a mutable Uri instance with the instance it was cloned from

public __clone() : void

__construct()

Constructor

public __construct([Uri|string|null $uri = null ]) : mixed

Instantiate the request object

Parameters
$uri : Uri|string|null = null
Tags
throws
Exception

__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

getProtocolVersion()

Get the HTTP protocol version, per PSR-7

public getProtocolVersion() : string
Return values
string

getRequestTarget()

Get the request target, per PSR-7 (path + query, or '/' with no URI, unless overridden)

public getRequestTarget() : string
Return values
string

getUri()

Get URI, per PSR-7 (a transient, never-stored empty Uri when none is set, so hasUri() remains unaffected by calling this)

public getUri() : Uri
Return values
Uri

getUriAsString()

Get URI as string

public getUriAsString() : string
Return values
string

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

withProtocolVersion()

Return an instance with the specified HTTP protocol version, per PSR-7

public withProtocolVersion(string $version) : static
Parameters
$version : string
Return values
static

withRequestTarget()

Return an instance with the specified request target, per PSR-7

public withRequestTarget(string $requestTarget) : static
Parameters
$requestTarget : string
Return values
static

withUri()

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

public withUri(UriInterface $uri[, bool $preserveHost = false ]) : static
Parameters
$uri : UriInterface
$preserveHost : bool = false
Return values
static

        
On this page

Search results