\FACTFinder\UtilParameters

Represents parameters with string values, where each parameter can have one or multiple values (like URL query parameters). For basic functions it can be used as an array, but also provides add() methods to add subsequent values to a key. So it really is just an array with multiple values per key. The class also comes with a few convenience functions to convert to and from other parameter representations (like query strings or HTTP headers).

Concept, interface and usage are partly inspired by .NET's NameValueCollection.

TODO: Implement Iterator or IteratorAggregate interface to allow use of Parameter objects in foreach(). Or maybe just extend ArrayIterator.

Summary

Methods
Properties
Constants
__construct()
offsetSet()
offsetExists()
offsetGet()
offsetUnset()
count()
getArray()
clear()
setAll()
set()
addAll()
add()
toPhpQueryString()
toJavaQueryString()
toHttpHeaderFields()
No public properties found
No constants found
sanitizeValue()
addString()
addArray()
$parameters
N/A
parseFromPhpQueryString()
parseFromJavaQueryString()
No private properties found
N/A

Properties

$parameters

$parameters : 

Type

Methods

__construct()

__construct(mixed  $parameters = null, boolean  $java = false) 

Optionally takes a URL query string or an array of initial parameters to populate the object with.

In the case of an array this is just a convenience over creating an empty object and setting the parameters manually with ->setAll($parameters).

Parameters

mixed $parameters

Either a URL query string or an array of parameters to initialize the object with.

boolean $java

If $parameters is a string and this is True, the query string will be interpreted as one originating from Java instead of PHP.

offsetSet()

offsetSet(string  $name, mixed  $value) 

Sets a parameter with one or multiple values.

Parameters

string $name

The parameter name.

mixed $value

A string or an array of strings. Nested arrays are not allowed. All other types are cast to strings.

Throws

\FACTFinder\Util\InvalidArgumentException

if no name is given or the value is a nested array.

offsetExists()

offsetExists(string  $name) : boolean

Checks if a parameter has any values set.

Parameters

string $name

The parameter name.

Returns

boolean

offsetGet()

offsetGet(string  $name) : mixed

Gets a parameter's value(s).

Parameters

string $name

The parameter name.

Throws

\FACTFinder\Util\InvalidArgumentException

if the name has no values set.

Returns

mixed —

The parameter's value(s). Either a single string or an array of multiple strings.

offsetUnset()

offsetUnset(string  $name) 

Clears all values for the given parameter.

Parameters

string $name

The parameter name.

count()

count() : integer

Returns the number of values (not parameter names) stored in this object.

Returns

integer

getArray()

getArray() : array<mixed,mixed>

Returns a reference to the object's internal array used to store all parameters. This can be used to sort the parameters from the outside.

TODO: Provide access to relevant functions instead. Just handing out the array is kind of dangerous and also breaks all encapsulation.

Returns

array<mixed,mixed> —

An array of all parameters. All values are either strings or arrays of strings.

clear()

clear() 

Deletes all parameters.

setAll()

setAll(array<mixed,mixed>  $parameters) 

Set all given parameters. Previous values of the given parameters will be replaced. Unmentioned parameters will retain their values.

Parameters

array<mixed,mixed> $parameters

An array of parameters. The keys are parameter names, the values are like those you would pass to offsetSet().

set()

set(string  $name, mixed  $value) 

Alias for $parameters['name'] = 'value' notation, because offset indexing cannot be chained with method calls.

Parameters

string $name

The parameter name.

mixed $value

A string or an array of strings. Nested arrays are not allowed. All other types are cast to strings.

Throws

\FACTFinder\Util\InvalidArgumentException

if no name is given or the value is a nested array.

addAll()

addAll(array<mixed,mixed>  $parameters) 

Adds all given parameter values in addition to all existing values.

Parameters

array<mixed,mixed> $parameters

An array of parameters. The keys are parameter names, the values are like those you would pass to offsetSet().

add()

add(string  $name, mixed  $value) 

Adds a parameter value. As opposed to offsetSet() existing values will not be replaced.

Parameters

string $name

The parameter name.

mixed $value

A string or an array of strings. Nested arrays are not allowed. All other types are cast to strings.

Throws

\FACTFinder\Util\InvalidArgumentException

if no name is given or the value is a nested array.

toPhpQueryString()

toPhpQueryString() : string

Returns a URL query string based on the set parameters for use in a request to a PHP server. That is, PHP's built-in functions will correctly recreate the structure of this object's internal array.

Note however, that PHP will replace all non-letter, non-digit characters in parameter names with underscores, when retrieving GET parameters. WARNING: If the parameter object contains the empty string as one of its keys, the corresponding key-value pair(s) will be part of the query string. However, PHP's built-in functions will not be able retrieve those values (this includes $_GET and parse_str()). However, if you create a new Parameters object from such a query string, the empty parameter names will be correctly reconstructed.

Returns

string —

The query string.

toJavaQueryString()

toJavaQueryString() : string

Returns a URL query string based on the set parameters for use in a request to a Java server. The difference to a PHP query string is that Java does not need and cannot deal with square brackets in parameter names. Hence, parameters with multiple names will simply be repeated.

Returns

string —

The query string.

toHttpHeaderFields()

toHttpHeaderFields() 

Returns an array of strings which are valid HTTP Header fields with field name and value. Multiple values are joined with commas as per RFC 2616.

sanitizeValue()

sanitizeValue(mixed  $value) : mixed

Makes sure that the given value is not a nested array. It also converts all non-strings to strings. Lastly, single-element arrays are converted to string values.

Parameters

mixed $value

The value to be sanitized.

Returns

mixed —

The sanitized value.

addString()

addString(  $name,   $value) 

Parameters

$name
$value

addArray()

addArray(  $name,   $value) 

Parameters

$name
$value

parseFromPhpQueryString()

parseFromPhpQueryString(  $query) 

Parameters

$query

parseFromJavaQueryString()

parseFromJavaQueryString(  $query) 

Parameters

$query