Symfony2 API
Class

Symfony\Component\HttpFoundation\ResponseHeaderBag

class ResponseHeaderBag extends HeaderBag

ResponseHeaderBag is a container for Response HTTP headers.

Constants

COOKIES_FLAT

COOKIES_ARRAY

DISPOSITION_ATTACHMENT

DISPOSITION_INLINE

Methods

__construct(array $headers = array())

Constructor.

string __toString()

Returns the headers as a string.

array all()

Returns the headers.

from HeaderBag
array keys()

Returns the parameter keys.

from HeaderBag
replace(array $headers = array())

Replaces the current HTTP headers by a new set.

add(array $headers)

Adds new headers the current HTTP headers set.

from HeaderBag
string|array get(string $key, mixed $default = null, bool $first = true)

Returns a header value by name.

from HeaderBag
set(string $key, string|array $values, bool $replace = true)

Sets a header by name.

bool has(string $key)

Returns true if the HTTP header is defined.

from HeaderBag
bool contains(string $key, string $value)

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

from HeaderBag
remove(string $key)

Removes a header.

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

Returns the HTTP header value converted to a date.

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

Adds a custom Cache-Control directive.

from HeaderBag
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.

from HeaderBag
ArrayIterator getIterator()

Returns an iterator for headers.

from HeaderBag
int count()

Returns the number of headers.

from HeaderBag
array allPreserveCase()

Returns the headers, with original capitalizations.

setCookie(Cookie $cookie)

Sets a cookie.

removeCookie(string $name, string $path = '/', string $domain = null)

Removes a cookie from the array, but does not unset it in the browser

array getCookies(string $format = self::COOKIES_FLAT)

Returns an array with all cookies

clearCookie(string $name, string $path = '/', string $domain = null, bool $secure = false, bool $httpOnly = true)

Clears a cookie in the browser

string makeDisposition(string $disposition, string $filename, string $filenameFallback = '')

Generates a HTTP Content-Disposition field-value.

Details

at line 51
public __construct(array $headers = array())

Constructor.

Parameters

array $headers An array of HTTP headers

at line 63
public string __toString()

Returns the headers as a string.

Return Value

string The headers

in HeaderBag at line 71
public array all()

Returns the headers.

Return Value

array An array of headers

in HeaderBag at line 83
public array keys()

Returns the parameter keys.

Return Value

array An array of parameter keys

at line 90
public replace(array $headers = array())

Replaces the current HTTP headers by a new set.

Parameters

array $headers An array of HTTP headers

in HeaderBag at line 108
public add(array $headers)

Adds new headers the current HTTP headers set.

Parameters

array $headers An array of HTTP headers

in HeaderBag at line 126
public string|array get(string $key, mixed $default = null, bool $first = true)

Returns a header value by name.

Parameters

string $key The header name
mixed $default The default value
bool $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 106
public set(string $key, string|array $values, bool $replace = true)

Sets a header by name.

Parameters

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

in HeaderBag at line 180
public 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

in HeaderBag at line 195
public 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 127
public remove(string $key)

Removes a header.

Parameters

string $key The HTTP header name

in HeaderBag at line 230
public 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

in HeaderBag at line 249
public 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 142
public 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 150
public 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

in HeaderBag at line 285
public removeCacheControlDirective(string $key)

Removes a Cache-Control directive.

Parameters

string $key The Cache-Control directive

in HeaderBag at line 297
public ArrayIterator getIterator()

Returns an iterator for headers.

Return Value

ArrayIterator An \ArrayIterator instance

in HeaderBag at line 307
public int count()

Returns the number of headers.

Return Value

int The number of headers

at line 80
public array allPreserveCase()

Returns the headers, with original capitalizations.

Return Value

array An array of headers

at line 162
public setCookie(Cookie $cookie)

Sets a cookie.

Parameters

Cookie $cookie

at line 176
public removeCookie(string $name, string $path = '/', string $domain = null)

Removes a cookie from the array, but does not unset it in the browser

Parameters

string $name
string $path
string $domain

at line 204
public array getCookies(string $format = self::COOKIES_FLAT)

Returns an array with all cookies

Parameters

string $format

Return Value

array

Exceptions

InvalidArgumentException When the $format is invalid

at line 237
public clearCookie(string $name, string $path = '/', string $domain = null, bool $secure = false, bool $httpOnly = true)

Clears a cookie in the browser

Parameters

string $name
string $path
string $domain
bool $secure
bool $httpOnly

at line 256
public string makeDisposition(string $disposition, string $filename, string $filenameFallback = '')

Generates a HTTP Content-Disposition field-value.

Parameters

string $disposition One of "inline" or "attachment"
string $filename A unicode string
string $filenameFallback A string containing only ASCII characters that is semantically equivalent to $filename. If the filename is already ASCII, it can be omitted, or just copied from $filename

Return Value

string A string suitable for use as a Content-Disposition field-value.

Exceptions

InvalidArgumentException

See also

RFC 6266