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

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.
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 like parse_str without mangling the results.
extractFromValue()  : array<string|int, mixed>
Parses the query string like parse_str without mangling the results.
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
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.

Constants

PAIR_VALUE_DECODED

private mixed PAIR_VALUE_DECODED = 1

PAIR_VALUE_PRESERVED

private mixed PAIR_VALUE_PRESERVED = 2

Methods

build()

Build a query string from a list of pairs.

public static build(iterable<string|int, array{0: string, 1: string|float|int|bool|null}> $pairs[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC3986 ]) : string|null
Parameters
$pairs : iterable<string|int, array{0: string, 1: string|float|int|bool|null}>
$separator : non-empty-string = '&'
$encType : int = PHP_QUERY_RFC3986
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: string|float|int|bool|null}> $pairs[, Converter|null $converter = null ]) : 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: string|float|int|bool|null}>
$converter : Converter|null = null
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

convert()

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) : array<string|int, mixed>
Parameters
$pairs : iterable<string|int, mixed>
Return values
array<string|int, mixed>

extract()

Parses the query string like parse_str without mangling the results.

public static extract(Stringable|string|bool|null $query[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC3986 ]) : array<string|int, mixed>
Parameters
$query : Stringable|string|bool|null
$separator : non-empty-string = '&'
$encType : int = PHP_QUERY_RFC3986
Tags
see
QueryString::extractFromValue()
see
http://php.net/parse_str
see
https://wiki.php.net/rfc/on_demand_name_mangling
throws
SyntaxError
Return values
array<string|int, mixed>

extractFromValue()

Parses the query string like parse_str without mangling the results.

public static extractFromValue(Stringable|string|bool|null $query[, Converter|null $converter = null ]) : array<string|int, mixed>

The result is similar as PHP parse_str when used with its second argument with the difference that variable names are not mangled.

Parameters
$query : Stringable|string|bool|null
$converter : Converter|null = null
Tags
see
http://php.net/parse_str
see
https://wiki.php.net/rfc/on_demand_name_mangling
throws
SyntaxError
Return values
array<string|int, mixed>

parse()

Parses a query string into a collection of key/value pairs.

public static parse(Stringable|string|bool|null $query[, non-empty-string $separator = '&' ][, int $encType = PHP_QUERY_RFC3986 ]) : array<int, array{0: string, 1: string|null}>
Parameters
$query : 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(Stringable|string|bool|null $query[, Converter|null $converter = null ]) : array<int, array{0: string, 1: string|null}>
Parameters
$query : 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

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 = '' ]) : 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

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