class ResponseHeaderBag extends HeaderBag

ResponseHeaderBag is a container for Response HTTP headers.

Constants

COOKIES_FLAT

COOKIES_ARRAY

DISPOSITION_ATTACHMENT

DISPOSITION_INLINE

Properties

protected $headers from HeaderBag
protected $cacheControl from HeaderBag
protected $computedCacheControl
protected $cookies
protected $headerNames

Methods

__construct(array $headers = array())

No description

string
__toString()

Returns the headers as a string.

from HeaderBag
array
all()

Returns the headers.

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

Returns a header value by name.

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

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.

DateTime|null
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
getIterator()

Returns an iterator for headers.

from HeaderBag
int
count()

Returns the number of headers.

from HeaderBag
getCacheControlHeader()

No description

from HeaderBag
array
parseCacheControl(string $header)

Parses a Cache-Control HTTP header.

from HeaderBag
array
allPreserveCase()

Returns the headers, with original capitalizations.

setCookie(Cookie $cookie)

No description

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

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

Cookie[]
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.

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

No description

string
computeCacheControlValue()

Returns the calculated value of the cache-control header.

Details

__construct(array $headers = array())

Parameters

array $headers An array of HTTP headers

string __toString()

Returns the headers as a string.

Return Value

string The headers

array all()

Returns the headers.

Return Value

array An array of headers

array keys()

Returns the parameter keys.

Return Value

array An array of parameter keys

replace(array $headers = array())

Replaces the current HTTP headers by a new set.

Parameters

array $headers An array of HTTP headers

add(array $headers)

Adds new headers the current HTTP headers set.

Parameters

array $headers An array of HTTP headers

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

Returns a header value by name.

Parameters

string $key The header name
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

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)

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

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

remove(string $key)

Removes a header.

Parameters

string $key The HTTP header name

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

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

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

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

removeCacheControlDirective(string $key)

Removes a Cache-Control directive.

Parameters

string $key The Cache-Control directive

ArrayIterator getIterator()

Returns an iterator for headers.

Return Value

ArrayIterator An \ArrayIterator instance

int count()

Returns the number of headers.

Return Value

int The number of headers

protected getCacheControlHeader()

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

array allPreserveCase()

Returns the headers, with original capitalizations.

Return Value

array An array of headers

allPreserveCaseWithoutCookies()

setCookie(Cookie $cookie)

Parameters

Cookie $cookie

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

Cookie[] getCookies(string $format = self::COOKIES_FLAT)

Returns an array with all cookies.

Parameters

string $format

Return Value

Cookie[]

Exceptions

InvalidArgumentException When the $format is invalid

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

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

Parameters

$disposition
$filename
$filenameFallback

See also

protected string computeCacheControlValue()

Returns the calculated value of the cache-control header.

This considers several other headers and calculates or modifies the cache-control header to a sensible, conservative value.

Return Value

string