Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ailixter/gears-filter
The project, which gears Filter functions.
https://github.com/ailixter/gears-filter
component config conversion filter input parameters php request sanitization typecast validation
Last synced: 18 days ago
JSON representation
The project, which gears Filter functions.
- Host: GitHub
- URL: https://github.com/ailixter/gears-filter
- Owner: ailixter
- License: mit
- Created: 2018-10-20T16:38:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-17T13:56:33.000Z (over 5 years ago)
- Last Synced: 2024-11-17T05:18:02.327Z (3 months ago)
- Topics: component, config, conversion, filter, input, parameters, php, request, sanitization, typecast, validation
- Language: PHP
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gears-filter
The project, which gears Filter functions.Casts
- variable
- input GET, POST, etc.
- arrayCast $var into $type.
``` php
$filter = new Filter;
$int1 = $filter->cast(FILTER_VALIDATE_INT, '123');
$int2 = $filter->cast(['filter'=>FILTER_VALIDATE_INT, 'flags'=>...], '123');
$int3 = $filter->cast('int', '123');
```Cast input $key into $type.
``` php
$filter = new Filter;
$int1 = $filter->castInput(FILTER_VALIDATE_INT, INPUT_POST, 'p');
$int2 = $filter->castInput(['filter'=>FILTER_VALIDATE_INT, 'flags'=>...], INPUT_POST, 'p');
$int3 = $filter->castInput('int', INPUT_POST, 'p');
```Utility Filter-based class ArrayFilter
``` php
$array = new ArrayFilter(['a' => 123, 'b' => 'false'], new Filter);
$bool = $array->get('bool', 'b');
$float = $array->getFloat('a', 0.0);
$custom = $array->getCustomType('a');
$all = $array->castAll(['a' => 'float', 'b' => 'bool', 'undefined' => 'str']);
```Utility Filter-based class InputFilter
``` php
$post = new InputFilter(INPUT_POST, new Filter);
$bool = $post->get('bool', 'b');
$float = $post->getFloat('a', 0.0);
$custom = $post->getCustomType('a');
$all = $post->castAll(['a' => 'float', 'b' => 'bool', 'undefined' => 'str']);
```