Piwik\

Request

Provides (type safe) access methods for request parameters.

Ensure to handle parameters received with this class with care. Especially parameters received as string, array or json might contain malicious content. Those should never be used raw in templates or other output.

Note: For security reasons this class will automatically remove null byte sequences from string values.

Methods

The class defines the following methods:

  • __construct()
  • fromRequest() — Creates a request object using GET and POST parameters of the current request
  • fromGet() — Creates a request object using only GET parameters of the current request
  • fromPost() — Creates a request object using only POST parameters of the current request
  • fromQueryString() — Creates a request object using the parameters that can be extracted from the provided query string
  • getParameter() — Returns the requested parameter from the request object.
  • getIntegerParameter() — Returns the requested parameter from the request object.
  • getFloatParameter() — Returns the requested parameter from the request object.
  • getStringParameter() — Returns the requested parameter from the request object.
  • getBoolParameter() — Returns the requested parameter from the request object.
  • getArrayParameter() — Returns the requested parameter from the request object.
  • getJsonParameter() — Returns the requested parameter from the request object.
  • getParameters() — Returns an array containing all parameters of the request object

__construct()

Signature

  • It accepts the following parameter(s):
    • $requestParameters (array) —

fromRequest()

Creates a request object using GET and POST parameters of the current request

Signature

fromGet()

Creates a request object using only GET parameters of the current request

Signature

fromPost()

Creates a request object using only POST parameters of the current request

Signature

fromQueryString()

Creates a request object using the parameters that can be extracted from the provided query string

Signature

  • It accepts the following parameter(s):

    • $queryString (string) —
  • It returns a Request value.

getParameter()

Returns the requested parameter from the request object.

If the requested parameter can't be found and no default is provided an exception will be thrown

Note: It's recommend to use one of type-safe methods instead, if a certain type is expected:

See Also

  • getIntegerParameter
  • getFloatParameter
  • getStringParameter
  • getArrayParameter
  • getJSONParameter

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (mixed) —

  • It returns a mixed value.

  • It throws one of the following exceptions:

getIntegerParameter()

Returns the requested parameter from the request object.

If no default is provided and the requested parameter either can't be found or is not of type integer an exception will be thrown

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (int|null) —

  • It returns a int value.

  • It throws one of the following exceptions:

getFloatParameter()

Returns the requested parameter from the request object.

If no default is provided and the requested parameter either can't be found or is not of type float an exception will be thrown

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (float|null) —

  • It returns a float value.

  • It throws one of the following exceptions:

getStringParameter()

Returns the requested parameter from the request object.

If no default is provided and the requested parameter either can't be found or is not of type string an exception will be thrown

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (string|null) —

  • It returns a string value.

  • It throws one of the following exceptions:

getBoolParameter()

Returns the requested parameter from the request object.

If no default is provided and the requested parameter either can't be found or can't be converted to boolean exception will be thrown

Values accepted as bool-ish: true: true, 'true', '1', 1 false: false, 'false', '0', 0

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (bool|null) —

  • It returns a bool value.

  • It throws one of the following exceptions:

getArrayParameter()

Returns the requested parameter from the request object.

If no default is provided and the requested parameter either can't be found or is not of type array an exception will be thrown

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (array|null) —

  • It returns a array value.

  • It throws one of the following exceptions:

getJsonParameter()

Returns the requested parameter from the request object.

If no default is provided and the requested parameter either can't be found or can't be json_decode'd an exception will be thrown

Signature

  • It accepts the following parameter(s):

    • $name (string) —

    • $default (mixed) —

  • It returns a mixed value.

  • It throws one of the following exceptions:

getParameters()

Returns an array containing all parameters of the request object

Signature

  • It returns a array value.