class HeaderBag implements IteratorAggregate, Countable

HeaderBag is a container for HTTP headers.

Properties

protected $headers
protected $cacheControl

Methods

__construct(array $headers = array())

No description

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|string[]|null
get(string $key, string|string[]|null $default = null, bool $first = true)

Returns a header value by name.

set(string $key, string|string[] $values, bool $replace = true)

Sets a header by name.

bool
has(string $key)

Returns true if the HTTP header is defined.

bool
contains(string $key, string $value)

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

remove(string $key)

Removes a header.

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

Returns the HTTP header value converted to a date.

addCacheControlDirective(string $key, mixed $value = true)

Adds a custom Cache-Control directive.

bool
hasCacheControlDirective(string $key)

Returns true if the Cache-Control directive is defined.

mixed|null
getCacheControlDirective(string $key)

Returns a Cache-Control directive value by name.

removeCacheControlDirective(string $key)

Removes a Cache-Control directive.

getIterator()

Returns an iterator for headers.

int
count()

Returns the number of headers.

getCacheControlHeader()

No description

array
parseCacheControl(string $header)

Parses a Cache-Control HTTP header.

Details

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

Parameters

array $headers An array of HTTP headers

at line 39
string __toString()

Returns the headers as a string.

Return Value

string The headers

at line 63
array all()

Returns the headers.

Return Value

array An array of headers

at line 73
array keys()

Returns the parameter keys.

Return Value

array An array of parameter keys

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

Replaces the current HTTP headers by a new set.

Parameters

array $headers An array of HTTP headers

at line 94
add(array $headers)

Adds new headers the current HTTP headers set.

Parameters

array $headers An array of HTTP headers

at line 110
string|string[]|null get(string $key, string|string[]|null $default = null, bool $first = true)

Returns a header value by name.

Parameters

string $key The header name
string|string[]|null $default The default value
bool $first Whether to return the first value or all header values

Return Value

string|string[]|null The first header value or default value if $first is true, an array of values otherwise

at line 136
set(string $key, string|string[] $values, bool $replace = true)

Sets a header by name.

Parameters

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

at line 160
bool has(string $key)

Returns true if the HTTP header is defined.

Parameters

string $key The HTTP header

Return Value

bool true if the parameter exists, false otherwise

at line 173
bool 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

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

at line 183
remove(string $key)

Removes a header.

Parameters

string $key The HTTP header name

at line 204
DateTime|null 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

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

Exceptions

RuntimeException When the HTTP header is not parseable

at line 223
addCacheControlDirective(string $key, mixed $value = true)

Adds a custom Cache-Control directive.

Parameters

string $key The Cache-Control directive name
mixed $value The Cache-Control directive value

at line 237
bool hasCacheControlDirective(string $key)

Returns true if the Cache-Control directive is defined.

Parameters

string $key The Cache-Control directive

Return Value

bool true if the directive exists, false otherwise

at line 249
mixed|null getCacheControlDirective(string $key)

Returns a Cache-Control directive value by name.

Parameters

string $key The directive name

Return Value

mixed|null The directive value if defined, null otherwise

at line 259
removeCacheControlDirective(string $key)

Removes a Cache-Control directive.

Parameters

string $key The Cache-Control directive

at line 271
ArrayIterator getIterator()

Returns an iterator for headers.

Return Value

ArrayIterator An \ArrayIterator instance

at line 281
int count()

Returns the number of headers.

Return Value

int The number of headers

at line 286
protected getCacheControlHeader()

at line 312
protected array parseCacheControl(string $header)

Parses a Cache-Control HTTP header.

Parameters

string $header The value of the Cache-Control HTTP header

Return Value

array An array representing the attribute values