ResponseHeaderBag
extends HeaderBag
in package
ResponseHeaderBag is a container for Response HTTP headers.
Tags
Table of Contents
Constants
- COOKIES_ARRAY = 'array'
- COOKIES_FLAT = 'flat'
- DISPOSITION_ATTACHMENT = 'attachment'
- DISPOSITION_INLINE = 'inline'
- LOWER = '-abcdefghijklmnopqrstuvwxyz'
- UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Properties
- $cacheControl : mixed
- $computedCacheControl : mixed
- $cookies : mixed
- $headerNames : mixed
- $headers : array<string, array<int, string|null>>
Methods
- __construct() : mixed
- __toString() : string
- Returns the headers as a string.
- add() : mixed
- Adds new headers the current HTTP headers set.
- addCacheControlDirective() : mixed
- Adds a custom Cache-Control directive.
- all() : array<string, array<int, string|null>>|array<int, string|null>
- Returns the headers.
- allPreserveCase() : array<string|int, mixed>
- Returns the headers, with original capitalizations.
- allPreserveCaseWithoutCookies() : mixed
- clearCookie() : mixed
- Clears a cookie in the browser.
- contains() : bool
- Returns true if the given HTTP header contains the given value.
- count() : int
- Returns the number of headers.
- get() : string|null
- Returns the first header by name or the default one.
- getCacheControlDirective() : bool|string|null
- Returns a Cache-Control directive value by name.
- getCookies() : array<string|int, Cookie>
- Returns an array with all cookies.
- getDate() : DateTimeInterface|null
- Returns the HTTP header value converted to a date.
- getIterator() : ArrayIterator<string, array<int, string|null>>
- Returns an iterator for headers.
- has() : bool
- Returns true if the HTTP header is defined.
- hasCacheControlDirective() : bool
- Returns true if the Cache-Control directive is defined.
- keys() : array<string|int, string>
- Returns the parameter keys.
- makeDisposition() : mixed
- remove() : mixed
- Removes a header.
- removeCacheControlDirective() : mixed
- Removes a Cache-Control directive.
- removeCookie() : mixed
- Removes a cookie from the array, but does not unset it in the browser.
- replace() : mixed
- Replaces the current HTTP headers by a new set.
- set() : mixed
- Sets a header by name.
- setCookie() : mixed
- computeCacheControlValue() : string
- Returns the calculated value of the cache-control header.
- getCacheControlHeader() : mixed
- parseCacheControl() : array<string|int, mixed>
- Parses a Cache-Control HTTP header.
- initDate() : void
Constants
COOKIES_ARRAY
public
mixed
COOKIES_ARRAY
= 'array'
COOKIES_FLAT
public
mixed
COOKIES_FLAT
= 'flat'
DISPOSITION_ATTACHMENT
public
mixed
DISPOSITION_ATTACHMENT
= 'attachment'
DISPOSITION_INLINE
public
mixed
DISPOSITION_INLINE
= 'inline'
LOWER
protected
mixed
LOWER
= '-abcdefghijklmnopqrstuvwxyz'
UPPER
protected
mixed
UPPER
= '_ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Properties
$cacheControl
protected
mixed
$cacheControl
= []
$computedCacheControl
protected
mixed
$computedCacheControl
= []
$cookies
protected
mixed
$cookies
= []
$headerNames
protected
mixed
$headerNames
= []
$headers
protected
array<string, array<int, string|null>>
$headers
= []
Methods
__construct()
public
__construct([array<string|int, mixed> $headers = [] ]) : mixed
Parameters
- $headers : array<string|int, mixed> = []
__toString()
Returns the headers as a string.
public
__toString() : string
Return values
stringadd()
Adds new headers the current HTTP headers set.
public
add(array<string|int, mixed> $headers) : mixed
Parameters
- $headers : array<string|int, mixed>
addCacheControlDirective()
Adds a custom Cache-Control directive.
public
addCacheControlDirective(string $key[, bool|string $value = true ]) : mixed
Parameters
- $key : string
- $value : bool|string = true
all()
Returns the headers.
public
all([string $key = null ]) : array<string, array<int, string|null>>|array<int, string|null>
Parameters
- $key : string = null
-
The name of the headers to return or null to get them all
Return values
array<string, array<int, string|null>>|array<int, string|null>allPreserveCase()
Returns the headers, with original capitalizations.
public
allPreserveCase() : array<string|int, mixed>
Return values
array<string|int, mixed>allPreserveCaseWithoutCookies()
public
allPreserveCaseWithoutCookies() : mixed
clearCookie()
Clears a cookie in the browser.
public
clearCookie(string $name[, string|null $path = '/' ][, string $domain = null ][, bool $secure = false ][, bool $httpOnly = true ][, string $sameSite = null ]) : mixed
Parameters
- $name : string
- $path : string|null = '/'
- $domain : string = null
- $secure : bool = false
- $httpOnly : bool = true
- $sameSite : string = null
contains()
Returns true if the given HTTP header contains the given value.
public
contains(string $key, string $value) : bool
Parameters
- $key : string
- $value : string
Return values
boolcount()
Returns the number of headers.
public
count() : int
Return values
intget()
Returns the first header by name or the default one.
public
get(string $key[, string $default = null ]) : string|null
Parameters
- $key : string
- $default : string = null
Return values
string|nullgetCacheControlDirective()
Returns a Cache-Control directive value by name.
public
getCacheControlDirective(string $key) : bool|string|null
Parameters
- $key : string
Return values
bool|string|nullgetCookies()
Returns an array with all cookies.
public
getCookies([string $format = self::COOKIES_FLAT ]) : array<string|int, Cookie>
Parameters
- $format : string = self::COOKIES_FLAT
Tags
Return values
array<string|int, Cookie>getDate()
Returns the HTTP header value converted to a date.
public
getDate(string $key[, DateTime $default = null ]) : DateTimeInterface|null
Parameters
- $key : string
- $default : DateTime = null
Tags
Return values
DateTimeInterface|nullgetIterator()
Returns an iterator for headers.
public
getIterator() : ArrayIterator<string, array<int, string|null>>
Return values
ArrayIterator<string, array<int, string|null>>has()
Returns true if the HTTP header is defined.
public
has(string $key) : bool
Parameters
- $key : string
Return values
boolhasCacheControlDirective()
Returns true if the Cache-Control directive is defined.
public
hasCacheControlDirective(string $key) : bool
Parameters
- $key : string
Return values
boolkeys()
Returns the parameter keys.
public
keys() : array<string|int, string>
Return values
array<string|int, string>makeDisposition()
public
makeDisposition(string $disposition, string $filename[, string $filenameFallback = '' ]) : mixed
Parameters
- $disposition : string
- $filename : string
- $filenameFallback : string = ''
Tags
remove()
Removes a header.
public
remove(string $key) : mixed
Parameters
- $key : string
removeCacheControlDirective()
Removes a Cache-Control directive.
public
removeCacheControlDirective(string $key) : mixed
Parameters
- $key : string
removeCookie()
Removes a cookie from the array, but does not unset it in the browser.
public
removeCookie(string $name[, string|null $path = '/' ][, string $domain = null ]) : mixed
Parameters
- $name : string
- $path : string|null = '/'
- $domain : string = null
replace()
Replaces the current HTTP headers by a new set.
public
replace([array<string|int, mixed> $headers = [] ]) : mixed
Parameters
- $headers : array<string|int, mixed> = []
set()
Sets a header by name.
public
set(string $key, string|array<string|int, mixed>|null $values[, bool $replace = true ]) : mixed
Parameters
- $key : string
- $values : string|array<string|int, mixed>|null
-
The value or an array of values
- $replace : bool = true
-
Whether to replace the actual value or not (true by default)
setCookie()
public
setCookie(Cookie $cookie) : mixed
Parameters
- $cookie : Cookie
computeCacheControlValue()
Returns the calculated value of the cache-control header.
protected
computeCacheControlValue() : string
This considers several other headers and calculates or modifies the cache-control header to a sensible, conservative value.
Return values
stringgetCacheControlHeader()
protected
getCacheControlHeader() : mixed
parseCacheControl()
Parses a Cache-Control HTTP header.
protected
parseCacheControl(string $header) : array<string|int, mixed>
Parameters
- $header : string
Return values
array<string|int, mixed>initDate()
private
initDate() : void