class HeaderBag implements IteratorAggregate, Countable

HeaderBag is a container for HTTP headers.

Methods

__construct(array $headers = array())

Constructor.

string
__toString()

Returns the headers as a string.

array
all()

Returns the headers.

array
keys()

Returns the parameter keys.

replace(array $headers = array())

Replaces the current HTTP headers by a new set.

add(array $headers)

Adds new headers the current HTTP headers set.

string|array
get(string $key, mixed $default = null, Boolean $first = true)

Returns a header value by name.

set(string $key, string|array $values, Boolean $replace = true)

Sets a header by name.

Boolean
has(string $key)

Returns true if the HTTP header is defined.

Boolean
contains(string $key, string $value)

Returns true if the given HTTP header contains the given value.

remove(string $key)

Removes a header.

null|DateTime
getDate(string $key, DateTime $default = null)

Returns the HTTP header value converted to a date.

addCacheControlDirective($key, $value = true)

No description

hasCacheControlDirective($key)

No description

getCacheControlDirective($key)

No description

removeCacheControlDirective($key)

No description

getIterator()

Returns an iterator for headers.

int
count()

Returns the number of headers.

Details

at line line 33
__construct(array $headers = array())

Constructor.

Parameters

array $headers An array of HTTP headers

at line line 47
string __toString()

Returns the headers as a string.

Return Value

string The headers

at line line 73
array all()

Returns the headers.

Return Value

array An array of headers

at line line 85
array keys()

Returns the parameter keys.

Return Value

array An array of parameter keys

at line line 97
replace(array $headers = array())

Replaces the current HTTP headers by a new set.

Parameters

array $headers An array of HTTP headers

at line line 110
add(array $headers)

Adds new headers the current HTTP headers set.

Parameters

array $headers An array of HTTP headers

at line line 128
string|array get(string $key, mixed $default = null, Boolean $first = true)

Returns a header value by name.

Parameters

string $key The header name
mixed $default The default value
Boolean $first Whether to return the first value or all header values

Return Value

string|array The first header value if $first is true, an array of values otherwise

at line line 156
set(string $key, string|array $values, Boolean $replace = true)

Sets a header by name.

Parameters

string $key The key
string|array $values The value or an array of values
Boolean $replace Whether to replace the actual value or not (true by default)

at line line 182
Boolean has(string $key)

Returns true if the HTTP header is defined.

Parameters

string $key The HTTP header

Return Value

Boolean true if the parameter exists, false otherwise

at line line 197
Boolean contains(string $key, string $value)

Returns true if the given HTTP header contains the given value.

Parameters

string $key The HTTP header name
string $value The HTTP value

Return Value

Boolean true if the value is contained in the header, false otherwise

at line line 209
remove(string $key)

Removes a header.

Parameters

string $key The HTTP header name

at line line 232
null|DateTime getDate(string $key, DateTime $default = null)

Returns the HTTP header value converted to a date.

Parameters

string $key The parameter key
DateTime $default The default value

Return Value

null|DateTime The parsed DateTime or the default value if the header does not exist

Exceptions

RuntimeException When the HTTP header is not parseable

at line line 245
addCacheControlDirective($key, $value = true)

Parameters

$key
$value

at line line 252
hasCacheControlDirective($key)

Parameters

$key

at line line 257
getCacheControlDirective($key)

Parameters

$key

at line line 262
removeCacheControlDirective($key)

Parameters

$key

at line line 274
ArrayIterator getIterator()

Returns an iterator for headers.

Return Value

ArrayIterator An \ArrayIterator instance

at line line 284
int count()

Returns the number of headers.

Return Value

int The number of headers