namespace \webfiori\http
class RequestParameter
Class Methods Summary
Class Methods Details
Parameters:
- string $name The name of the parameter as it appears in the request body. It must be a valid name. If the given name is invalid, the parameter name will be set to 'a-parameter'. Valid name must comply with the following rules:
- It can contain the letters [A-Z] and [a-z].
- It can contain the numbers [0-9].
- It can have the character '-' and the character '_'.
- string $type The type of the data that will be in the parameter stored by the parameter. Supported types are:
- string
- integer
- float
- url
- boolean
- array
- json-obj
- boolean $isOptional Set to true if the parameter is optional. Default is false.
RequestParameter[
Name =
Type =
Description =
Is Optional =
Default =
Minimum Value =
Maximum Value =
]
Parameters:
- array $options An associative array of options. The array can have the following indices:
- name: The name of the parameter. If invalid name is provided, the value 'a-parameter' is used. If it is not provided, no parameter will be created.
- type: The datatype of the parameter. If not provided, 'string' is used.
- optional: A boolean. If set to true, it means the parameter is optional. If not provided, 'false' is used.
- min: Minimum value of the parameter. Applicable only for numeric types.
- max: Maximum value of the parameter. Applicable only for numeric types.
- allow-empty: A boolean. If the type of the parameter is string or string-like type and this is set to true, then empty strings will be allowed. If not provided, 'false' is used.
- custom-filter: A PHP function that can be used to filter the parameter even further
- default: An optional default value to use if the parameter is not provided and is optional.
- description: The description of the attribute.
Sets a callback method to work as a filter for request parameter. The callback method will have 3 parameters passed to it:
- Original value without filtering.
- The value with basic filtering rules applied to it.
- An object of type RequestParameter.
If the parameter $applyBasicFilter is set to false, the second parameter will have the value 'NOT_APLICABLE'.
The object of type RequestParameter will contain original information for the filter.
The method must be implemented in a way that makes it return false or null if the parameter has invalid value. If the parameter is filtered and was validated, the method must return the valid and filtered value.Parameters:
- callback $function A callback function.
- boolean $applyBasicFilter If set to true, the basic filter will be applied to the parameter. Default is true.
Parameters:
- mixed $val default value for the parameter to use.
Parameters:
- string $desc Parameter description.
Parameters:
- boolean $bool true to allow empty strings and false to disallow empty strings.
Parameters:
- boolean $bool True to make the parameter optional. False to make it mandatory.
Sets the maximum value. The value will be updated only if:
- The request parameter type is numeric ('integer' or 'float').
- The given value is greater than RequestParameter::getMinVal()
Parameters:
- int $val The maximum value to set.
Sets the minimum value that the parameter can accept. The value will be updated only if:
- The request parameter type is numeric ('integer' or 'float').
- The given value is less than RequestParameter::getMaxVal()
Parameters:
- int $val The minimum value to set.
Sets the name of the parameter. A valid parameter name must follow the following rules:
- It can contain the letters [A-Z] and [a-z].
- It can contain the numbers [0-9].
- It can have the character '-' and the character '_'.
Parameters:
- string $name The name of the parameter.
Parameters:
- string $type The type of the parameter. It must be a value form the contats which exist in the class 'ParamTypes'.
Returns a Json object that represents the request parameter. This method is used to help front-end developers in showing the documentation of the request parameter. The format of JSON string will be as follows:
{
"name":"a-param",
"type":"string",
"description":null,
"is-optional":true,
"default-value":null,
"min-val":null,
"max-val":null
}