Documentation

QueryString
in package

FinalYes

A class to parse the URI query string.

Tags
see
https://tools.ietf.org/html/rfc3986#section-3.4

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
see
QueryString::buildFromPairs()
see
https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
throws
SyntaxError

If the encoding type is invalid

throws
SyntaxError

If a pair is invalid

Return values
string|null

buildFromPairs()

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
see
https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
throws
SyntaxError

If the encoding type is invalid

throws
SyntaxError

If a pair is invalid

Return values
string|null

compose()

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 null value (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
throws
TypeError

if a resource is found it the input array

throws
ValueError

if a recursion is detected

Return values
string|null

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
see
QueryString::extractFromValue()
throws
SyntaxError
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
throws
SyntaxError
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
throws
SyntaxError
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
throws
SyntaxError
Return values
array<int, array{0: string, 1: string|null}>

__construct()

private __construct() : mixed
Tags
codeCoverageIgnore

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
throws
TypeError

if a resource is found it the input array

throws
ValueError

if a recursion is detected

throws
ReflectionException

if reflection is not possible on the Enum

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
see
https://php.net/parse_str
see
https://wiki.php.net/rfc/on_demand_name_mangling
see
https://github.com/php/php-src/blob/master/ext/standard/tests/strings/parse_str_basic1.phpt
see
https://github.com/php/php-src/blob/master/ext/standard/tests/strings/parse_str_basic2.phpt
see
https://github.com/php/php-src/blob/master/ext/standard/tests/strings/parse_str_basic3.phpt
see
https://github.com/php/php-src/blob/master/ext/standard/tests/strings/parse_str_basic4.phpt
Return values
array<string|int, mixed>

        
On this page

Search results