AbstractRequest
extends AbstractRequestResponse
in package
implements
RequestInterface
Abstract HTTP request class
Tags
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
$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
= []
$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
$uri
Request URI object
protected
Uri|null
$uri
= 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
__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
AbstractRequestResponseclearUri()
Clear URI
public
clearUri() : AbstractRequest
Return values
AbstractRequestdecodeBodyContent()
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|nullgetProtocolVersion()
Get the HTTP protocol version, per PSR-7
public
getProtocolVersion() : string
Return values
stringgetRequestTarget()
Get the request target, per PSR-7 (path + query, or '/' with no URI, unless overridden)
public
getRequestTarget() : string
Return values
stringgetUri()
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
UrigetUriAsString()
Get URI as string
public
getUriAsString() : string
Return values
stringhasBody()
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
boolhasUri()
Has URI
public
hasUri() : 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
AbstractRequestResponsesetUri()
Set URI
public
setUri(Uri|string $uri) : AbstractRequest
Parameters
- $uri : Uri|string
Tags
Return values
AbstractRequestwithAddedHeader()
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
staticwithProtocolVersion()
Return an instance with the specified HTTP protocol version, per PSR-7
public
withProtocolVersion(string $version) : static
Parameters
- $version : string
Return values
staticwithRequestTarget()
Return an instance with the specified request target, per PSR-7
public
withRequestTarget(string $requestTarget) : static
Parameters
- $requestTarget : string
Return values
staticwithUri()
Return an instance with the specified URI, per PSR-7
public
withUri(UriInterface $uri[, bool $preserveHost = false ]) : static
Parameters
- $uri : UriInterface
- $preserveHost : bool = false