Constants

UPPER

UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ'

LOWER

LOWER = '-abcdefghijklmnopqrstuvwxyz'

COOKIES_FLAT

COOKIES_FLAT = 'flat'

COOKIES_ARRAY

COOKIES_ARRAY = 'array'

DISPOSITION_ATTACHMENT

DISPOSITION_ATTACHMENT = 'attachment'

DISPOSITION_INLINE

DISPOSITION_INLINE = 'inline'

Properties

$headers

$headers : array<string,list<string|null>>

Type

array>

$cacheControl

$cacheControl

$computedCacheControl

$computedCacheControl

$cookies

$cookies

$headerNames

$headerNames

Methods

__construct()

__construct(array  $headers = []) : mixed

Parameters

array $headers

Returns

mixed —

__toString()

__toString() : string

Returns the headers as a string.

Returns

string —

all()

all(string  $key = null) : array<string,array<int,string|null>>|array<int,string|null>

Returns the headers.

Parameters

string $key

The name of the headers to return or null to get them all

Returns

array>|array

keys()

keys() : string[]

Returns the parameter keys.

Returns

string[] —

replace()

replace(array  $headers = []) : mixed

Replaces the current HTTP headers by a new set.

Parameters

array $headers

Returns

mixed —

add()

add(array  $headers) : mixed

Adds new headers the current HTTP headers set.

Parameters

array $headers

Returns

mixed —

get()

get(string  $key, string  $default = null) : string|null

Returns the first header by name or the default one.

Parameters

string $key
string $default

Returns

string|null —

set()

set(string  $key, mixed  $values, bool  $replace = true) : mixed

Sets a header by name.

Parameters

string $key
mixed $values

The value or an array of values

bool $replace

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

Returns

mixed —

has()

has(string  $key) : bool

Returns true if the HTTP header is defined.

Parameters

string $key

Returns

bool —

contains()

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

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

Parameters

string $key
string $value

Returns

bool —

remove()

remove(string  $key) : mixed

Removes a header.

Parameters

string $key

Returns

mixed —

getDate()

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

Returns the HTTP header value converted to a date.

Parameters

string $key
\DateTime $default

Throws

\RuntimeException

When the HTTP header is not parseable

Returns

\DateTimeInterface|null —

addCacheControlDirective()

addCacheControlDirective(string  $key, bool|string  $value = true) : mixed

Adds a custom Cache-Control directive.

Parameters

string $key
bool|string $value

The Cache-Control directive value

Returns

mixed —

hasCacheControlDirective()

hasCacheControlDirective(string  $key) : bool

Returns true if the Cache-Control directive is defined.

Parameters

string $key

Returns

bool —

getCacheControlDirective()

getCacheControlDirective(string  $key) : bool|string|null

Returns a Cache-Control directive value by name.

Parameters

string $key

Returns

bool|string|null —

removeCacheControlDirective()

removeCacheControlDirective(string  $key) : mixed

Removes a Cache-Control directive.

Parameters

string $key

Returns

mixed —

getIterator()

getIterator() : \ArrayIterator<string,list<string|null>>

Returns an iterator for headers.

Returns

\ArrayIterator> —

count()

count() : int

Returns the number of headers.

Returns

int —

allPreserveCase()

allPreserveCase() : array

Returns the headers, with original capitalizations.

Returns

array —

allPreserveCaseWithoutCookies()

allPreserveCaseWithoutCookies() : mixed

Returns

mixed —

setCookie()

setCookie(\Symfony\Component\HttpFoundation\Cookie  $cookie) : mixed

Parameters

\Symfony\Component\HttpFoundation\Cookie $cookie

Returns

mixed —

removeCookie()

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

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

Parameters

string $name
?string $path
string $domain

Returns

mixed —

getCookies()

getCookies(string  $format = self::COOKIES_FLAT) : \Symfony\Component\HttpFoundation\Cookie[]

Returns an array with all cookies.

Parameters

string $format

Throws

\InvalidArgumentException

When the $format is invalid

Returns

\Symfony\Component\HttpFoundation\Cookie[] —

clearCookie()

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

Clears a cookie in the browser.

Parameters

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

Returns

mixed —

makeDisposition()

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

Parameters

string $disposition
string $filename
string $filenameFallback

Returns

mixed —

getCacheControlHeader()

getCacheControlHeader() : mixed

Returns

mixed —

parseCacheControl()

parseCacheControl(string  $header) : array

Parses a Cache-Control HTTP header.

Parameters

string $header

Returns

array —

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 —

initDate()

initDate() : void