FilterInput
in package
This is the FilterInput class.
The purpose of this class is to filter (validate and sanitize) the given values according to the given filter configuration.
Use examples: It is commonly used to filter the parameters of a request,...
Tags
Table of Contents
CONFIGURATION_ALLOW_EMPTY | = 'allowEmpty' | |
---|---|---|
CONFIGURATION_DATE_TIME_FORMAT | = 'dateTimeFormat' | |
CONFIGURATION_FILTER_KEY_ALLOW_TAGS | = 'allowTags' | |
CONFIGURATION_FILTER_KEY_AVAILABLE_VALUES | = 'availableValues' | |
CONFIGURATION_FILTER_KEY_ENABLE_MODIFICATION | = 'enableModification' | |
CONFIGURATION_FILTER_KEY_FILTER_FLAGS | = 'filterFlags' | |
CONFIGURATION_FILTER_KEY_FILTER_SANITIZE_ID | = 'filterSanitizeId' | |
CONFIGURATION_FILTER_KEY_FILTER_VALIDATE_ID | = 'filterValidateId' | |
CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR | = 'functionValidator' | |
CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR_EXPLONDE_PARAM_SEPARATOR | = 'functionValidatorExplondeParamSeparator' | |
CONFIGURATION_FILTER_KEY_REGEX_VALIDATE | = 'regexValidate' | |
CONFIGURATION_FILTER_KEY_STRING_FORMAT | = 'strFormat' | |
CONFIGURATION_NO_FILTER | = 'noFilter' | |
REGEX_VALIDATE_FLOAT_RANGE | = '/^([0-9]*[.])?[0-9]+' . self::REGEX_VALIDATE_RANGE_SEPARATOR . '([0-9]*[.])?[0-9]+$/' | |
REGEX_VALIDATE_INT_LIST | = '/^(([0-9](,)?)*)+$/' | |
REGEX_VALIDATE_INT_RANGE | = '/^[0-9]+' . self::REGEX_VALIDATE_RANGE_SEPARATOR . '[0-9]+$/' | |
REGEX_VALIDATE_INTERVAL | = '/^([0-9]*[.])?[0-9]+' . self::REGEX_VALIDATE_RANGE_SEPARATOR . '([0-9]*[.])?[0-9]+$|^(([0-9]*[.])?[0-9])$/' | |
REGEX_VALIDATE_RANGE_SEPARATOR | = ';' | |
REGEX_VALIDATE_SORT_DIRECTION | = '/^' . \SDK\Enums\ProductSort::SORT_DIRECTION_ASC . '$|^' . \SDK\Enums\ProductSort::SORT_DIRECTION_DESC . '$/' | |
STR_FORMAT_CAPITAL | = 3 | |
STR_FORMAT_HTML_CLEAR | = 4 | |
STR_FORMAT_TO_LOWER | = 1 | |
STR_FORMAT_TO_UPPER | = 2 | |
__construct() | Constructor method. | : mixed |
getConfiguartionFilter() | : array<string|int, mixed> | |
getFilterValue() | This method applies the filter (validation and sanitization) to the given value according to the set filter configuration. | : null|string |
stripTags() | : string |
Constants
CONFIGURATION_ALLOW_EMPTY
public
mixed
CONFIGURATION_ALLOW_EMPTY
= 'allowEmpty'
CONFIGURATION_DATE_TIME_FORMAT
public
mixed
CONFIGURATION_DATE_TIME_FORMAT
= 'dateTimeFormat'
CONFIGURATION_FILTER_KEY_ALLOW_TAGS
public
mixed
CONFIGURATION_FILTER_KEY_ALLOW_TAGS
= 'allowTags'
CONFIGURATION_FILTER_KEY_AVAILABLE_VALUES
public
mixed
CONFIGURATION_FILTER_KEY_AVAILABLE_VALUES
= 'availableValues'
CONFIGURATION_FILTER_KEY_ENABLE_MODIFICATION
public
mixed
CONFIGURATION_FILTER_KEY_ENABLE_MODIFICATION
= 'enableModification'
CONFIGURATION_FILTER_KEY_FILTER_FLAGS
public
mixed
CONFIGURATION_FILTER_KEY_FILTER_FLAGS
= 'filterFlags'
CONFIGURATION_FILTER_KEY_FILTER_SANITIZE_ID
public
mixed
CONFIGURATION_FILTER_KEY_FILTER_SANITIZE_ID
= 'filterSanitizeId'
CONFIGURATION_FILTER_KEY_FILTER_VALIDATE_ID
public
mixed
CONFIGURATION_FILTER_KEY_FILTER_VALIDATE_ID
= 'filterValidateId'
CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR
public
mixed
CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR
= 'functionValidator'
CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR_EXPLONDE_PARAM_SEPARATOR
public
mixed
CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR_EXPLONDE_PARAM_SEPARATOR
= 'functionValidatorExplondeParamSeparator'
CONFIGURATION_FILTER_KEY_REGEX_VALIDATE
public
mixed
CONFIGURATION_FILTER_KEY_REGEX_VALIDATE
= 'regexValidate'
CONFIGURATION_FILTER_KEY_STRING_FORMAT
public
mixed
CONFIGURATION_FILTER_KEY_STRING_FORMAT
= 'strFormat'
CONFIGURATION_NO_FILTER
public
mixed
CONFIGURATION_NO_FILTER
= 'noFilter'
REGEX_VALIDATE_FLOAT_RANGE
public
mixed
REGEX_VALIDATE_FLOAT_RANGE
= '/^([0-9]*[.])?[0-9]+' . self::REGEX_VALIDATE_RANGE_SEPARATOR . '([0-9]*[.])?[0-9]+$/'
REGEX_VALIDATE_INT_LIST
public
mixed
REGEX_VALIDATE_INT_LIST
= '/^(([0-9](,)?)*)+$/'
REGEX_VALIDATE_INT_RANGE
public
mixed
REGEX_VALIDATE_INT_RANGE
= '/^[0-9]+' . self::REGEX_VALIDATE_RANGE_SEPARATOR . '[0-9]+$/'
REGEX_VALIDATE_INTERVAL
public
mixed
REGEX_VALIDATE_INTERVAL
= '/^([0-9]*[.])?[0-9]+' . self::REGEX_VALIDATE_RANGE_SEPARATOR . '([0-9]*[.])?[0-9]+$|^(([0-9]*[.])?[0-9])$/'
REGEX_VALIDATE_RANGE_SEPARATOR
public
mixed
REGEX_VALIDATE_RANGE_SEPARATOR
= ';'
REGEX_VALIDATE_SORT_DIRECTION
public
mixed
REGEX_VALIDATE_SORT_DIRECTION
= '/^' . \SDK\Enums\ProductSort::SORT_DIRECTION_ASC . '$|^' . \SDK\Enums\ProductSort::SORT_DIRECTION_DESC . '$/'
STR_FORMAT_CAPITAL
public
mixed
STR_FORMAT_CAPITAL
= 3
STR_FORMAT_HTML_CLEAR
public
mixed
STR_FORMAT_HTML_CLEAR
= 4
STR_FORMAT_TO_LOWER
public
mixed
STR_FORMAT_TO_LOWER
= 1
STR_FORMAT_TO_UPPER
public
mixed
STR_FORMAT_TO_UPPER
= 2
Methods
__construct()
Constructor method.
public
__construct([array<string|int, mixed> $configuartionFilter = [] ]) : mixed
This method constructs a FilterInput with the given configuration.
You can set the following configuration keys for the FilterInput:
- FilterInput::CONFIGURATION_NO_FILTER ->To indicate whether or not to apply the filter. Possible values[true/false]. Default = false.
- FilterInput::CONFIGURATION_ALLOW_EMPTY ->To indicate whether or not allow empty values. Possible values[true/false]. Default = false.
- FilterInput::CONFIGURATION_DATE_TIME_FORMAT ->To indicate that the value to sanitize must return a DateTime object and the date time format to apply. Possible values: \DateTime const formats Default = null.
- FilterInput::CONFIGURATION_FILTER_KEY_ENABLE_MODIFICATION ->To indicate wheter or not to allow the modification of the original given value to be filtered. If false, then some sanitization actions can not be applied and in these cases the value will not pass de filter. Possible values[true/false]. Default = true.
- FilterInput::CONFIGURATION_FILTER_KEY_FILTER_SANITIZE_ID ->To indicate the php sanitization to be applied. Possible values[[](http://www.php.net/manual/en/filter.constants.php)]. Default = FILTER_UNSAFE_RAW. See reference [](https://www.php.net/manual/en/function.filter-var.php)
- FilterInput::CONFIGURATION_FILTER_KEY_FILTER_VALIDATE_ID ->If set, then the indicated php filter will be applied as part of the filter. Possible values[[](http://www.php.net/manual/en/filter.constants.php)]. Default = null. See reference [](https://www.php.net/manual/en/function.filter-var.php)
- FilterInput::CONFIGURATION_FILTER_KEY_FILTER_FLAGS ->To indicate the php options for the SANITIZE_ID and VALIDATE_ID (if filter/sanitization accepts options, an array of php flags can be provided). Possible values [see [](https://www.php.net/manual/en/function.filter-var.php)] Default = null.
- FilterInput::CONFIGURATION_FILTER_KEY_ALLOW_TAGS ->To indicate whether or not apply filter to avoid tags (HTML, js, XML or PHP). Possible values [true/false] Default = false.
- FilterInput::CONFIGURATION_FILTER_KEY_REGEX_VALIDATE ->If set, the provided regular expression will be applied as part of the filter. Possible values [The REGEX pattern to be checked, as a string]. Default = null.
- FilterInput::CONFIGURATION_FILTER_KEY_AVAILABLE_VALUES ->If set, this filter considers the value to be filtered as a string list sepparated by commas, and checks if all the elements of this list matches with the given set of valid values (set in this configuration) and sanitizes those that not match. Possible values [array of strings containing the set of possible values]. Default = null.
- FilterInput::CONFIGURATION_FILTER_KEY_STRING_FORMAT ->If set, then the returned filtered value will be formatted with the format indicated in this configuration option. Possible values [self::STR_FORMAT_CAPITAL, self::STR_FORMAT_TO_LOWER, self::STR_FORMAT_TO_UPPER, self::STR_FORMAT_HTML_CLEAR]. Default = null.
- FilterInput::CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR ->If set, then the function indicated in this configuration option will be passed as part of the filter. Possible values [a callable function] Default = null.
- FilterInput::CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR_EXPLONDE_PARAM_SEPARATOR ->Related to FilterInput::CONFIGURATION_FILTER_KEY_FUNCTION_VALIDATOR. If set, then the validated value will be splitted with the separator indicated in this configuration option and the splitted elements will be passed as a list of parameters to the function indicated in the FUNCTION_VALIDATOR configuration option. Default = null.
Parameters
- $configuartionFilter : array<string|int, mixed> = []
-
Configuration of the filter.
Return values
mixed —getConfiguartionFilter()
public
getConfiguartionFilter() : array<string|int, mixed>
Return values
array<string|int, mixed> —getFilterValue()
This method applies the filter (validation and sanitization) to the given value according to the set filter configuration.
public
getFilterValue(mixed $value) : null|string
If the value passes the filter then this method returns the filtered value, else it returns null.
Parameters
- $value : mixed
Return values
null|string —If the value don't passes the filter return null, else return the filtered value
stripTags()
public
stripTags(string $string) : string
Parameters
- $string : string