HeaderUtils
in package
HTTP header utility functions.
Tags
Table of Contents
- DISPOSITION_ATTACHMENT = 'attachment'
- DISPOSITION_INLINE = 'inline'
- combine() : array<string|int, mixed>
- Combines an array of arrays into one associative array.
- makeDisposition() : string
- Generates an HTTP Content-Disposition field-value.
- parseQuery() : array<string|int, mixed>
- Like parse_str(), but preserves dots in variable names.
- quote() : string
- Encodes a string as a quoted string, if necessary.
- split() : array<string|int, mixed>
- Splits an HTTP header by one or more separators.
- toString() : string
- Joins an associative array into a string for use in an HTTP header.
- unquote() : string
- Decodes a quoted string.
- __construct() : mixed
- This class should not be instantiated.
- groupParts() : array<string|int, mixed>
Constants
DISPOSITION_ATTACHMENT
public
mixed
DISPOSITION_ATTACHMENT
= 'attachment'
DISPOSITION_INLINE
public
mixed
DISPOSITION_INLINE
= 'inline'
Methods
combine()
Combines an array of arrays into one associative array.
public
static combine(array<string|int, mixed> $parts) : array<string|int, mixed>
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
- $parts : array<string|int, mixed>
Return values
array<string|int, mixed> —makeDisposition()
Generates an HTTP Content-Disposition field-value.
public
static makeDisposition(string $disposition, string $filename[, string $filenameFallback = '' ]) : string
Parameters
- $disposition : string
-
One of "inline" or "attachment"
- $filename : string
-
A unicode string
- $filenameFallback : string = ''
-
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
Tags
Return values
string —parseQuery()
Like parse_str(), but preserves dots in variable names.
public
static parseQuery(string $query[, bool $ignoreBrackets = false ][, string $separator = '&' ]) : array<string|int, mixed>
Parameters
- $query : string
- $ignoreBrackets : bool = false
- $separator : string = '&'
Return values
array<string|int, mixed> —quote()
Encodes a string as a quoted string, if necessary.
public
static quote(string $s) : string
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
- $s : string
Return values
string —split()
Splits an HTTP header by one or more separators.
public
static split(string $header, string $separators) : array<string|int, mixed>
Example:
HeaderUtils::split('da, en-gb;q=0.8', ',;') // => ['da'], ['en-gb', 'q=0.8']]
Parameters
- $header : string
- $separators : string
-
List of characters to split on, ordered by precedence, e.g. ',', ';=', or ',;='
Return values
array<string|int, mixed> —Nested array with as many levels as there are characters in $separators
toString()
Joins an associative array into a string for use in an HTTP header.
public
static toString(array<string|int, mixed> $assoc, string $separator) : string
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
- $assoc : array<string|int, mixed>
- $separator : string
Return values
string —unquote()
Decodes a quoted string.
public
static unquote(string $s) : string
If passed an unquoted string that matches the "token" construct (as defined in the HTTP specification), it is passed through verbatim.
Parameters
- $s : string
Return values
string —__construct()
This class should not be instantiated.
private
__construct() : mixed
Return values
mixed —groupParts()
private
static groupParts(array<string|int, mixed> $matches, string $separators[, bool $first = true ]) : array<string|int, mixed>
Parameters
- $matches : array<string|int, mixed>
- $separators : string
- $first : bool = true