\Symfony\Component\HttpFoundationHeaderBag

HeaderBag is a container for HTTP headers.

Summary

Methods
Properties
Constants
__construct()
__toString()
all()
keys()
replace()
add()
get()
set()
has()
contains()
remove()
getDate()
addCacheControlDirective()
hasCacheControlDirective()
getCacheControlDirective()
removeCacheControlDirective()
getIterator()
count()
No public properties found
No constants found
getCacheControlHeader()
parseCacheControl()
$headers
$cacheControl
N/A
No private methods found
No private properties found
N/A

Properties

$headers

$headers : 

Type

$cacheControl

$cacheControl : 

Type

Methods

__construct()

__construct(array  $headers = array()) 

Parameters

array $headers

An array of HTTP headers

__toString()

__toString() : string

Returns the headers as a string.

Returns

string —

The headers

all()

all() : array

Returns the headers.

Returns

array —

An array of headers

keys()

keys() : array

Returns the parameter keys.

Returns

array —

An array of parameter keys

replace()

replace(array  $headers = array()) 

Replaces the current HTTP headers by a new set.

Parameters

array $headers

An array of HTTP headers

add()

add(array  $headers) 

Adds new headers the current HTTP headers set.

Parameters

array $headers

An array of HTTP headers

get()

get(string  $key, string|array<mixed,string>|null  $default = null, boolean  $first = true) : string|array<mixed,string>|null

Returns a header value by name.

Parameters

string $key

The header name

string|array<mixed,string>|null $default

The default value

boolean $first

Whether to return the first value or all header values

Returns

string|array<mixed,string>|null —

The first header value or default value if $first is true, an array of values otherwise

set()

set(string  $key, string|array<mixed,string>  $values, boolean  $replace = true) 

Sets a header by name.

Parameters

string $key

The key

string|array<mixed,string> $values

The value or an array of values

boolean $replace

Whether to replace the actual value or not (true by default)

has()

has(string  $key) : boolean

Returns true if the HTTP header is defined.

Parameters

string $key

The HTTP header

Returns

boolean —

true if the parameter exists, false otherwise

contains()

contains(string  $key, string  $value) : boolean

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

Parameters

string $key

The HTTP header name

string $value

The HTTP value

Returns

boolean —

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

remove()

remove(string  $key) 

Removes a header.

Parameters

string $key

The HTTP header name

getDate()

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

Returns the HTTP header value converted to a date.

Parameters

string $key

The parameter key

\DateTime $default

The default value

Throws

\RuntimeException

When the HTTP header is not parseable

Returns

null|\DateTime —

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

addCacheControlDirective()

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

hasCacheControlDirective()

hasCacheControlDirective(string  $key) : boolean

Returns true if the Cache-Control directive is defined.

Parameters

string $key

The Cache-Control directive

Returns

boolean —

true if the directive exists, false otherwise

getCacheControlDirective()

getCacheControlDirective(string  $key) : mixed|null

Returns a Cache-Control directive value by name.

Parameters

string $key

The directive name

Returns

mixed|null —

The directive value if defined, null otherwise

removeCacheControlDirective()

removeCacheControlDirective(string  $key) 

Removes a Cache-Control directive.

Parameters

string $key

The Cache-Control directive

getIterator()

getIterator() : \ArrayIterator

Returns an iterator for headers.

Returns

\ArrayIterator —

An \ArrayIterator instance

count()

count() : integer

Returns the number of headers.

Returns

integer —

The number of headers

getCacheControlHeader()

getCacheControlHeader() 

parseCacheControl()

parseCacheControl(string  $header) : array

Parses a Cache-Control HTTP header.

Parameters

string $header

The value of the Cache-Control HTTP header

Returns

array —

An array representing the attribute values