QueryString
in package
A class to parse the URI query string.
Tags
Table of Contents
Constants
- PAIR_VALUE_DECODED = 1
- PAIR_VALUE_PRESERVED = 2
- RECURSION_MARKER = "\x00__RECURSION_INTERNAL_MARKER__\x00"
Methods
- build() : string|null
- Build a query string from a list of pairs.
- buildFromPairs() : string|null
- Build a query string from a list of pairs.
- compose() : string|null
- Build a query string from an object or an array like http_build_query without discarding values.
- composeFromValue() : string|null
- convert() : array<string|int, mixed>
- Converts a collection of key/value pairs and returns the store PHP variables as elements of an array.
- extract() : array<string|int, mixed>
- Parses the query string.
- extractFromValue() : array<string|int, mixed>
- Parses the query string.
- parse() : array<int, array{0: string, 1: string|null}>
- Parses a query string into a collection of key/value pairs.
- parseFromValue() : array<int, array{0: string, 1: string|null}>
- Parses a query string into a collection of key/value pairs.
- __construct() : mixed
- composeRecursive() : iterable<string|int, array{0: array-key, 1: string|int|float|bool|null}>
- decodePairs() : array<int, array{0: string, 1: string|null}>
- extractPhpVariable() : array<string|int, mixed>
- Parses a query pair like parse_str without mangling the results array keys.
- hasCircularReference() : bool
- Array recursion detection.
Constants
PAIR_VALUE_DECODED
private
mixed
PAIR_VALUE_DECODED
= 1
PAIR_VALUE_PRESERVED
private
mixed
PAIR_VALUE_PRESERVED
= 2
RECURSION_MARKER
private
mixed
RECURSION_MARKER
= "\x00__RECURSION_INTERNAL_MARKER__\x00"
Methods
build()
Build a query string from a list of pairs.
public
static build(iterable<string|int, array{0: string, 1: mixed}> $pairs[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC3986 ][, StringCoercionMode $coercionMode = StringCoercionMode::Native ]) : string|null
Parameters
- $pairs : iterable<string|int, array{0: string, 1: mixed}>
- $separator : non-empty-string = '&'
- $encType : int = PHP_QUERY_RFC3986
- $coercionMode : StringCoercionMode = StringCoercionMode::Native
Tags
Return values
string|nullbuildFromPairs()
Build a query string from a list of pairs.
public
static buildFromPairs(iterable<string|int, array{0: string, 1: mixed}> $pairs[, Converter|null $converter = null ][, StringCoercionMode $coercionMode = StringCoercionMode::Native ]) : string|null
The method expects the return value from Query::parse to build a valid query string. This method differs from PHP http_build_query as it does not modify parameters keys.
If a reserved character is found in a URI component and no delimiting role is known for that character, then it must be interpreted as representing the data octet corresponding to that character's encoding in US-ASCII.
Parameters
- $pairs : iterable<string|int, array{0: string, 1: mixed}>
- $converter : Converter|null = null
- $coercionMode : StringCoercionMode = StringCoercionMode::Native
Tags
Return values
string|nullcompose()
Build a query string from an object or an array like http_build_query without discarding values.
public
static compose(array<string|int, mixed> $data[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC1738 ][, QueryComposeMode $composeMode = QueryComposeMode::Native ]) : string|null
The method differs from http_build_query for the following behavior:
- if a resource is used, a TypeError is thrown.
- if a recursion is detected a ValueError is thrown
- the method preserves value with
nullvalue (http_build_query) skip the key. - the method does not handle prefix usage
Parameters
- $data : array<string|int, mixed>
- $separator : non-empty-string = '&'
- $encType : int = PHP_QUERY_RFC1738
- $composeMode : QueryComposeMode = QueryComposeMode::Native
Tags
Return values
string|nullcomposeFromValue()
public
static composeFromValue(array<string|int, mixed>|object $data[, Converter|null $converter = null ][, QueryComposeMode $composeMode = QueryComposeMode::Native ]) : string|null
Parameters
- $data : array<string|int, mixed>|object
- $converter : Converter|null = null
- $composeMode : QueryComposeMode = QueryComposeMode::Native
Return values
string|nullconvert()
Converts a collection of key/value pairs and returns the store PHP variables as elements of an array.
public
static convert(iterable<string|int, mixed> $pairs[, QueryExtractMode $extractMode = QueryExtractMode::Unmangled ]) : array<string|int, mixed>
Parameters
- $pairs : iterable<string|int, mixed>
- $extractMode : QueryExtractMode = QueryExtractMode::Unmangled
Return values
array<string|int, mixed>extract()
Parses the query string.
public
static extract(BackedEnum|Stringable|string|bool|null $query[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC3986 ][, QueryExtractMode $extractMode = QueryExtractMode::Unmangled ]) : array<string|int, mixed>
The result depends on the query parsing mode
Parameters
- $query : BackedEnum|Stringable|string|bool|null
- $separator : non-empty-string = '&'
- $encType : int = PHP_QUERY_RFC3986
- $extractMode : QueryExtractMode = QueryExtractMode::Unmangled
Tags
Return values
array<string|int, mixed>extractFromValue()
Parses the query string.
public
static extractFromValue(BackedEnum|Stringable|string|bool|null $query[, Converter|null $converter = null ][, QueryExtractMode $extractMode = QueryExtractMode::Unmangled ]) : array<string|int, mixed>
The result depends on the query parsing mode
Parameters
- $query : BackedEnum|Stringable|string|bool|null
- $converter : Converter|null = null
- $extractMode : QueryExtractMode = QueryExtractMode::Unmangled
Tags
Return values
array<string|int, mixed>parse()
Parses a query string into a collection of key/value pairs.
public
static parse(BackedEnum|Stringable|string|bool|null $query[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC3986 ]) : array<int, array{0: string, 1: string|null}>
Parameters
- $query : BackedEnum|Stringable|string|bool|null
- $separator : non-empty-string = '&'
- $encType : int = PHP_QUERY_RFC3986
Tags
Return values
array<int, array{0: string, 1: string|null}>parseFromValue()
Parses a query string into a collection of key/value pairs.
public
static parseFromValue(BackedEnum|Stringable|string|bool|null $query[, Converter|null $converter = null ]) : array<int, array{0: string, 1: string|null}>
Parameters
- $query : BackedEnum|Stringable|string|bool|null
- $converter : Converter|null = null
Tags
Return values
array<int, array{0: string, 1: string|null}>__construct()
private
__construct() : mixed
Tags
composeRecursive()
private
static composeRecursive(QueryComposeMode $composeMode, array<string|int, mixed>|object $data[, string|int $prefix = '' ][, SplObjectStorage<object, null> $seenObjects = new SplObjectStorage() ]) : iterable<string|int, array{0: array-key, 1: string|int|float|bool|null}>
Parameters
- $composeMode : QueryComposeMode
- $data : array<string|int, mixed>|object
- $prefix : string|int = ''
- $seenObjects : SplObjectStorage<object, null> = new SplObjectStorage()
Tags
Return values
iterable<string|int, array{0: array-key, 1: string|int|float|bool|null}>decodePairs()
private
static decodePairs(array<string|int, array<int, string|null>> $pairs, int $pairValueState) : array<int, array{0: string, 1: string|null}>
Parameters
- $pairs : array<string|int, array<int, string|null>>
- $pairValueState : int
Return values
array<int, array{0: string, 1: string|null}>extractPhpVariable()
Parses a query pair like parse_str without mangling the results array keys.
private
static extractPhpVariable(array<string|int, mixed> $data, array<string|int, mixed>|string $name[, string $value = '' ][, QueryExtractMode $extractMode = QueryExtractMode::Unmangled ]) : array<string|int, mixed>
- empty name are not saved
- If the value from name is duplicated its corresponding value will be overwritten
- if no "[" is detected the value is added to the return array with the name as index
- if no "]" is detected after detecting a "[" the value is added to the return array with the name as index
- if there's a mismatch in bracket usage the remaining part is dropped
- “.” and “ ” are not converted to “_”
- If there is no “]”, then the first “[” is not converted to becomes an “_”
- no whitespace trimming is done on the key value
Parameters
- $data : array<string|int, mixed>
-
the submitted array
- $name : array<string|int, mixed>|string
-
the pair key
- $value : string = ''
-
the pair value
- $extractMode : QueryExtractMode = QueryExtractMode::Unmangled
Tags
Return values
array<string|int, mixed>hasCircularReference()
Array recursion detection.
private
static hasCircularReference(array<string|int, mixed> &$arr) : bool
Parameters
- $arr : array<string|int, mixed>