\Symfony\Component\HttpFoundationHeaderUtils

HTTP header utility functions.

Summary

Methods
Properties
Constants
split()
combine()
toString()
quote()
unquote()
makeDisposition()
parseQuery()
No public properties found
DISPOSITION_ATTACHMENT
DISPOSITION_INLINE
No protected methods found
No protected properties found
N/A
__construct()
groupParts()
No private properties found
N/A

Constants

DISPOSITION_ATTACHMENT

DISPOSITION_ATTACHMENT = 'attachment'

DISPOSITION_INLINE

DISPOSITION_INLINE = 'inline'

Methods

split()

split(string  $header, string  $separators) : array

Splits an HTTP header by one or more separators.

Example:

HeaderUtils::split("da, en-gb;q=0.8", ",;") // => ['da'], ['en-gb', 'q=0.8']]

Parameters

string $header
string $separators

List of characters to split on, ordered by precedence, e.g. ",", ";=", or ",;="

Returns

array —

Nested array with as many levels as there are characters in $separators

combine()

combine(array  $parts) : array

Combines an array of arrays into one associative array.

Each of the nested arrays should have one or two elements. The first value will be used as the keys in the associative array, and the second will be used as the values, or true if the nested array only contains one element. Array keys are lowercased.

Example:

HeaderUtils::combine([["foo", "abc"], ["bar"]])
// => ["foo" => "abc", "bar" => true]

Parameters

array $parts

Returns

array —

toString()

toString(array  $assoc, string  $separator) : string

Joins an associative array into a string for use in an HTTP header.

The key and value of each entry are joined with "=", and all entries are joined with the specified separator and an additional space (for readability). Values are quoted if necessary.

Example:

HeaderUtils::toString(["foo" => "abc", "bar" => true, "baz" => "a b c"], ",")
// => 'foo=abc, bar, baz="a b c"'

Parameters

array $assoc
string $separator

Returns

string —

quote()

quote(string  $s) : string

Encodes a string as a quoted string, if necessary.

If a string contains characters not allowed by the "token" construct in the HTTP specification, it is backslash-escaped and enclosed in quotes to match the "quoted-string" construct.

Parameters

string $s

Returns

string —

unquote()

unquote(string  $s) : string

Decodes a quoted string.

If passed an unquoted string that matches the "token" construct (as defined in the HTTP specification), it is passed through verbatim.

Parameters

string $s

Returns

string —

makeDisposition()

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

Generates an 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 —

parseQuery()

parseQuery(string  $query, bool  $ignoreBrackets = false, string  $separator = '&') : array

Like parse_str(), but preserves dots in variable names.

Parameters

string $query
bool $ignoreBrackets
string $separator

Returns

array —

__construct()

__construct() : mixed

This class should not be instantiated.

Returns

mixed —

groupParts()

groupParts(array  $matches, string  $separators, bool  $first = true) : array

Parameters

array $matches
string $separators
bool $first

Returns

array —