CodeIgniter v4.5 API

MessageTrait

Message Trait Additional methods to make a PSR-7 Message class compliant with the framework's own MessageInterface.

Tags
see
https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php

Table of Contents

Properties

$headerMap  : array<string|int, mixed>
Holds a map of lower-case header names and their normal-case key as it is in $headers.
$headers  : array<string, Header|array<int, Header>>
List of all HTTP request headers.

Methods

addHeader()  : $this
Adds a header (not a header value) with the same name.
appendBody()  : $this
Appends data to the body of the current message.
appendHeader()  : $this
Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
header()  : Header|array<int, Header>|null
Returns a single Header object. If multiple headers with the same name exist, then will return an array of header objects.
headers()  : array<string, Header|array<int, Header>>
Returns an array containing all Headers.
populateHeaders()  : void
Populates the $headers array with any headers the server knows about.
prependHeader()  : $this
Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
removeHeader()  : $this
Removes a header from the list of headers we track.
setBody()  : $this
Sets the body of the current message.
setHeader()  : $this
Sets a header and it's value.
setProtocolVersion()  : $this
Sets the HTTP protocol version.
getHeaderName()  : string
Takes a header name in any case, and returns the normal-case version of the header.
checkMultipleHeaders()  : void
hasMultipleHeaders()  : bool

Properties

$headerMap

Holds a map of lower-case header names and their normal-case key as it is in $headers.

protected array<string|int, mixed> $headerMap = []

Used for case-insensitive header access.

$headers

List of all HTTP request headers.

protected array<string, Header|array<int, Header>> $headers = []

[name => Header] or [name => [Header1, Header2]]

Methods

addHeader()

Adds a header (not a header value) with the same name.

public addHeader(string $name, string $value) : $this

Use this only when you set multiple headers with the same name, typically, for Set-Cookie.

Parameters
$name : string
$value : string
Return values
$this

appendBody()

Appends data to the body of the current message.

public appendBody(string $data) : $this
Parameters
$data : string
Return values
$this

appendHeader()

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

public appendHeader(string $name, string|null $value) : $this
Parameters
$name : string
$value : string|null
Return values
$this

header()

Returns a single Header object. If multiple headers with the same name exist, then will return an array of header objects.

public header(string $name) : Header|array<int, Header>|null
Parameters
$name : string
Return values
Header|array<int, Header>|null

headers()

Returns an array containing all Headers.

public headers() : array<string, Header|array<int, Header>>
Return values
array<string, Header|array<int, Header>>

An array of the Header objects

populateHeaders()

Populates the $headers array with any headers the server knows about.

public populateHeaders() : void

prependHeader()

Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)

public prependHeader(string $name, string $value) : $this
Parameters
$name : string
$value : string
Return values
$this

removeHeader()

Removes a header from the list of headers we track.

public removeHeader(string $name) : $this
Parameters
$name : string
Return values
$this

setBody()

Sets the body of the current message.

public setBody(string $data) : $this
Parameters
$data : string
Return values
$this

setHeader()

Sets a header and it's value.

public setHeader(string $name, array<string|int, mixed>|string|null $value) : $this
Parameters
$name : string
$value : array<string|int, mixed>|string|null
Return values
$this

setProtocolVersion()

Sets the HTTP protocol version.

public setProtocolVersion(string $version) : $this
Parameters
$version : string
Tags
throws
HTTPException

For invalid protocols

Return values
$this

getHeaderName()

Takes a header name in any case, and returns the normal-case version of the header.

protected getHeaderName(string $name) : string
Parameters
$name : string
Return values
string

checkMultipleHeaders()

private checkMultipleHeaders(string $name) : void
Parameters
$name : string

hasMultipleHeaders()

private hasMultipleHeaders(string $name) : bool
Parameters
$name : string
Return values
bool

        
On this page

Search results