Constants

COOKIES_FLAT

COOKIES_FLAT = 'flat'

COOKIES_ARRAY

COOKIES_ARRAY = 'array'

DISPOSITION_ATTACHMENT

DISPOSITION_ATTACHMENT = 'attachment'

DISPOSITION_INLINE

DISPOSITION_INLINE = 'inline'

Properties

$headers

$headers : 

Type

$cacheControl

$cacheControl : 

Type

$computedCacheControl

$computedCacheControl : 

Type

$cookies

$cookies : 

Type

$headerNames

$headerNames : 

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, mixed  $default = null, boolean  $first = true) : string|array

Returns a header value by name.

Parameters

string $key

The header name

mixed $default

The default value

boolean $first

Whether to return the first value or all header values

Returns

string|array —

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

set()

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

Sets a header by name.

Parameters

string $key

The key

string|array $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

allPreserveCase()

allPreserveCase() : array

Returns the headers, with original capitalizations.

Returns

array —

An array of headers

allPreserveCaseWithoutCookies()

allPreserveCaseWithoutCookies() 

removeCookie()

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

getCookies()

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

Returns an array with all cookies.

Parameters

string $format

Throws

\InvalidArgumentException

When the $format is invalid

Returns

array

clearCookie()

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

Clears a cookie in the browser.

Parameters

string $name
string $path
string $domain
boolean $secure
boolean $httpOnly

makeDisposition()

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

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

Throws

\InvalidArgumentException

Returns

string —

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

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

computeCacheControlValue()

computeCacheControlValue() : string

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.

Returns

string