IHeaders

Interface for HTTP headers wrapper.
Source
IHeaders.php
Extends
Iterator
Implementations
Headers

Static Methods

extractHeadersFromString

array IHeaders::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 IHeaders::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

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

remove

IHeaders $obj->remove(string header)

Remove a header.

Arguments

    header (string)
    The header-name

Returns

IHeaders
For method chaining

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"