Headers

This class is a wrapper around the and "HTTP headers". You can set/access response headers of a factory inheriting "IResponse" as "$this->Headers->set(...". The "IResponse" will create an instance or this class on demand when "->Headers" is used.
Note that "HTTP Request-Line" and "HTTP Status-Line" must be managed via request and response instances and are not by this class.
Source
Headers.php
Implements
IHeaders , Iterator
Depends on
IHeaders

Properties

httpRequestMethod

$obj->httpRequestMethod

When headers are being set if the string contains HTTP request method, it will be set to this property and not treated as a header. (The HTTP Request-Line).

httpRequestUrl

$obj->httpRequestUrl

When headers are being set if the string contains HTTP request URL, it will be set to this property and not treated as a header. (The HTTP Request-Line).

httpStatusCode

$obj->httpStatusCode

When headers are being set if the string contains HTTP status code, it will be set to this property and not treated as a header. (The HTTP Request-Line or Status-Line).

httpVersion

$obj->httpVersion

When headers are being set if the string contains HTTP version, it will be set to this property and not treated as a header. (The HTTP Status-Line).

Static Methods

extractHeadersFromString

array Headers::extractHeadersFromString(string headersStr, string separator="\r\n")

Extract headers from a string of headers separated by "\r\n". If a "Status-Line" or "Request-Line" exists in the header string then their data will be put in "__version__", "__status__", "__method__" and "__url__" keys.

Arguments

    headersStr (string)
    String of headers separated by \r\n.
    separator="\r\n" (string)
    Separator between the headers

Returns

array
{header-name: header-value, header-name: [header-values,],}

normaliseHeaderName

void Headers::normaliseHeaderName()

Normalise a header-name or header meta to a standard header-name.

Returns

void

Methods

__get

string|array __get(string header)

Get the value of a set header.

Arguments

    header (string)
    The header-name

Returns

string|array
The value set to the header or "null" if the header is not set

__isset

bool __isset(string header)

Check if a header has been been set.

Arguments

    header (string)
    The header-name

Returns

bool
If a header has been been set.

__set

void __set(string header, string | array value)

Set a header. If the header is already set it will be replaced.

Arguments

    header (string)
    The header-name
    value (string | array)
    Value to be set to the header

Returns

void

__toString

string __toString()

Get all headers as string.

Returns

string
The headers separated by "\r\n"

__unset

void __unset(string header)

Remove a header.

Arguments

    header (string)
    The header-name to be removed

Returns

void

add

IHeaders $obj->add(array | object header)

"httpRequestMethod" and "httpRequestUrl" properties in case you would need the, the values will be extracted into the "httpVersion", "httpStatusCode", and will not be added to the header list, however if they exist in the input Note that "Request-Line" and "Status-Line" will not be treated as headers to a standard header-name ('HTTP_' will be removed and '_' will be turned into '-'). can be set in more ways. In all cases each header-name will be normalised the new one, in contrast to "set()" which replaces the old ones). The headers Set a header (if a header is already set the old value will be extended with

Arguments

    header (array | object)
    A set of headers to be added as: {header-name: header-value, header-name: [header-value,],}

Returns

IHeaders
For method chaining

add

IHeaders $obj->add(string header)

"httpRequestMethod" and "httpRequestUrl" properties in case you would need the, the values will be extracted into the "httpVersion", "httpStatusCode", and will not be added to the header list, however if they exist in the input Note that "Request-Line" and "Status-Line" will not be treated as headers to a standard header-name ('HTTP_' will be removed and '_' will be turned into '-'). can be set in more ways. In all cases each header-name will be normalised the new one, in contrast to "set()" which replaces the old ones). The headers Set a header (if a header is already set the old value will be extended with

Arguments

    header (string)
    A string of headers separated by "\r\n"

Returns

IHeaders
For method chaining

add

IHeaders $obj->add(string header, string | array value)

"httpRequestMethod" and "httpRequestUrl" properties in case you would need the, the values will be extracted into the "httpVersion", "httpStatusCode", and will not be added to the header list, however if they exist in the input Note that "Request-Line" and "Status-Line" will not be treated as headers to a standard header-name ('HTTP_' will be removed and '_' will be turned into '-'). can be set in more ways. In all cases each header-name will be normalised the new one, in contrast to "set()" which replaces the old ones). The headers Set a header (if a header is already set the old value will be extended with

Arguments

    header (string)
    A header-name
    value (string | array)
    The value to be set to the header-name

Returns

IHeaders
For method chaining

clear

IHeaders $obj->clear()

Clear all set headers.

Returns

IHeaders
For method chaining

count

int $obj->count()

Get the number of set headers.

Returns

int
Number of set headers

current

string $obj->current()

Iterator - current.

Returns

string
Current header item

get

string|array $obj->get(string header)

Get the value set to a header-name.

Arguments

    header (string)
    The header-name

Returns

string|array
The value set to the header or "null" if the header is not set

has

bool $obj->has(string header)

Check if a header has been set.

Arguments

    header (string)
    The header-name

Returns

bool

key

int $obj->key()

Iterator - key.

Returns

int
Row number

next

string $obj->next()

Iterator - next.

Returns

string
Next header item

remove

IHeaders $obj->remove(string header)

Remove a header.

Arguments

    header (string)
    The header-name

Returns

IHeaders
For method chaining

rewind

void $obj->rewind()

Iterator - rewind.

Returns

void

send

bool $obj->send()

Send the headers.

Returns

bool
false=headers not sent because headers were already sent

set

IHeaders $obj->set(array | object header)

"httpRequestMethod" and "httpRequestUrl" properties in case you would need the, the values will be extracted into the "httpVersion", "httpStatusCode", and will not be added to the header list, however if they exist in the input Note that "Request-Line" and "Status-Line" will not be treated as headers to a standard header-name ('HTTP_' will be removed and '_' will be turned into '-'). can be set in more ways. In all cases each header-name will be normalised Set a header (if a header is already set it will be replaced). The headers

Arguments

    header (array | object)
    A set of headers to be added as: {header-name: header-value, header-name: [header-value,],}

Returns

IHeaders
For method chaining

set

IHeaders $obj->set(string header)

"httpRequestMethod" and "httpRequestUrl" properties in case you would need the, the values will be extracted into the "httpVersion", "httpStatusCode", and will not be added to the header list, however if they exist in the input Note that "Request-Line" and "Status-Line" will not be treated as headers to a standard header-name ('HTTP_' will be removed and '_' will be turned into '-'). can be set in more ways. In all cases each header-name will be normalised Set a header (if a header is already set it will be replaced). The headers

Arguments

    header (string)
    A string of headers separated by "\r\n"

Returns

IHeaders
For method chaining

set

IHeaders $obj->set(string header, string | array value)

"httpRequestMethod" and "httpRequestUrl" properties in case you would need the, the values will be extracted into the "httpVersion", "httpStatusCode", and will not be added to the header list, however if they exist in the input Note that "Request-Line" and "Status-Line" will not be treated as headers to a standard header-name ('HTTP_' will be removed and '_' will be turned into '-'). can be set in more ways. In all cases each header-name will be normalised Set a header (if a header is already set it will be replaced). The headers

Arguments

    header (string)
    A header-name
    value (string | array)
    The value to be set to the header-name

Returns

IHeaders
For method chaining

toString

string $obj->toString()

Get all headers as string.

Returns

string
The headers separated by "\r\n"

valid

bool $obj->valid()

Iterator - valid.

Returns

bool
true=is valid