From d291e86c4a52e6ab456fb32406042c7e0b0c9b58 Mon Sep 17 00:00:00 2001 From: Adrian Miu Date: Sat, 20 Jun 2015 08:55:11 +0300 Subject: [PATCH] Improved the documentation and moved it to coucous.io --- .gitattributes | 8 +++ .gitignore | 6 +- README.md | 22 +++---- docs/couscous.yml | 71 +++++++++++++++++++++++ docs/custom_filters.md | 43 ++++++++++++++ docs/filter_factory.md | 55 ++++++++++++++++++ docs/filters.md | 46 +++++++-------- docs/index.md | 64 ++++++++++++++++---- docs/installation.md | 21 +++++++ docs/{modeling.md => model_filtration.md} | 11 +++- docs/other.md | 54 ----------------- docs/output_filtration.md | 47 +++++++++++++++ docs/simple_example.md | 36 ++++++++++++ docs/special_selectors.md | 42 ++++++++++++++ docs/syntactic_sugar.md | 54 +++++++++++++++++ 15 files changed, 471 insertions(+), 109 deletions(-) create mode 100644 .gitattributes create mode 100644 docs/couscous.yml create mode 100644 docs/custom_filters.md create mode 100644 docs/filter_factory.md create mode 100644 docs/installation.md rename docs/{modeling.md => model_filtration.md} (90%) delete mode 100644 docs/other.md create mode 100644 docs/output_filtration.md create mode 100644 docs/simple_example.md create mode 100644 docs/special_selectors.md create mode 100644 docs/syntactic_sugar.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1251f8b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +/docs export-ignore +/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/couscous.yml export-ignore +/index.md export-ignore diff --git a/.gitignore b/.gitignore index 78d8fc0..3fb0efb 100755 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,7 @@ -INSTALL.txt -LICENSE.txt -README.txt -tests/report build /.settings /.buildpath /.project .idea/ +docs/.couscous +docs/couscous.phar diff --git a/README.md b/README.md index 4c66532..d9c7cbb 100755 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ #Sirius\Filtration -[![Build Status](https://travis-ci.org/siriusphp/filtration.png?branch=master)](https://travis-ci.org/siriusphp/filtration) -[![Coverage Status](https://coveralls.io/repos/siriusphp/filtration/badge.png)](https://coveralls.io/r/siriusphp/filtration) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/siriusphp/filtration/badges/quality-score.png?s=1897aacdd8313df10089c5307b336c0fde8624db)](https://scrutinizer-ci.com/g/siriusphp/filtration/) -[![Latest Stable Version](https://poser.pugx.org/siriusphp/filtration/version.png)](https://packagist.org/packages/siriusphp/filtration) -[![License](https://poser.pugx.org/siriusphp/filtration/license.png)](https://packagist.org/packages/siriusphp/filtration) +[![Source Code](http://img.shields.io/badge/source-siriusphp/filtration-blue.svg?style=flat-square)](https://github.com/siriusphp/filtration) +[![Latest Version](https://img.shields.io/packagist/v/siriusphp/filtration.svg?style=flat-square)](https://github.com/siriusphp/filtration/releases) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/siriusphp/filtration/blob/master/LICENSE) +[![Build Status](https://img.shields.io/travis/siriusphp/filtration/master.svg?style=flat-square)](https://travis-ci.org/siriusphp/filtration) +[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/siriusphp/filtration.svg?style=flat-square)](https://scrutinizer-ci.com/g/siriusphp/filtration/code-structure) +[![Quality Score](https://img.shields.io/scrutinizer/g/siriusphp/filtration.svg?style=flat-square)](https://scrutinizer-ci.com/g/siriusphp/filtration) PHP library for array filtering/sanitization @@ -55,13 +56,8 @@ array( */ ``` -##Why (just) arrays? -Arrays are easily exchangeable between components. User input (POST or GET) is an array, an object may be populated from an array, database query row can be an array, JSON data is passed from the client and gets to the server as an array. +##Links -##Documentation - -- [general usage of the library](docs/index.md) -- [built-in filters](docs/filters.md) -- [using SiriusFiltration with models](docs/modeling.md) -- [other usages for SiriusFiltration](docs/other.md) +- [documentation](http://www.sirius.ro/php/sirius/validation/) +- [changelog](CHANGELOG.md) diff --git a/docs/couscous.yml b/docs/couscous.yml new file mode 100644 index 0000000..f9797a3 --- /dev/null +++ b/docs/couscous.yml @@ -0,0 +1,71 @@ +template: + url: https://github.com/siriusphp/Template-ReadTheDocs + +# List of directories to exclude from the processing (default contains "vendor" and "website") +# Paths are relative to the repository root +exclude: + - website + - vendor + - test + - src + - build + +# Base URL of the published website (no "/" at the end!) +# You are advised to set and use this variable to write your links in the HTML layouts +baseUrl: http://www.sirius.ro/php/sirius/filtration + +projectName: Sirius\Filtration +title: Sirius\Filtration +subTitle: Framework agnostic data filtering library + +# The left menu bar +menu: + sections: +# versions: +# name: Versions +# items: +# two: +# text: "2.0" +# relativeUrl: +# one: +# text: "1.0" +# relativeUrl: 1_0/ + guide: + name: Getting started + items: + getting_started: + text: Introduction + relativeUrl: + installation: + text: Installation + relativeUrl: installation.html + simple_example: + text: Simple example + relativeUrl: simple_example.html + filters: + text: Built-in filters + relativeUrl: filters.html + syntactic_sugar: + text: Syntactic sugar + relativeUrl: syntactic_sugar.html + advanced: + name: Advanced topics + items: + special_selectors: + text: Special selectors + relativeUrl: special_selectors.html + custom_filter: + text: Custom filters + relativeUrl: custom_filters.html + filter_factory: + text: The filter factory + relativeUrl: filter_factory.html + cookbook: + name: Cookbook + items: + modeling: + text: Filtration for models + relativeUrl: model_filtration.html + outputing: + text: Filtration for output + relativeUrl: output_filtration.html diff --git a/docs/custom_filters.md b/docs/custom_filters.md new file mode 100644 index 0000000..99cf9cf --- /dev/null +++ b/docs/custom_filters.md @@ -0,0 +1,43 @@ +--- +title: Custom filters +--- + +# Custom filters + +Hopefully your app is complex enough to require you to build custom filters. Or you will find many uses for this library that you will have to build custom filters. + +Below is the code for a filter that adds a sequence of underscores in front of every item that is passed to it **if** the 'append_underscores' element from the context is true + +```php +namespace MyApp\Filtration\Filter; + +class AppendUnderscores extends Sirius\Filtration\Filter\AbstractFilter { + + function filterSingle($value, $valueIdentifier = null) { + // the context is passed to each filter and represents the entire dataset + // that was sent to be filtered + $no_of_underscores = (int) $this->context['append_underscores'] + return str_repeat('_', $no_of_underscores) . $value; + } + +} +``` + +And it is used like so + +```php +use Sirius\Filtration\Filtrator; +$filtrator = new Filtrator(); +$filtrator->add('content', 'MyApp\Filtration\Filter\AppendUnderscores'); + +$result = $filtrator->filter(array( + 'append_underscores' => 10, + 'content' => 'Pretty stupid, right?' +)); + +// $result will be +// array( +// 'append_underscores' => 10, +// 'content' => '_________Pretty stupid, right?' +// ) +``` \ No newline at end of file diff --git a/docs/filter_factory.md b/docs/filter_factory.md new file mode 100644 index 0000000..f0c3e09 --- /dev/null +++ b/docs/filter_factory.md @@ -0,0 +1,55 @@ +--- +title: The filter factory +--- + +# The filter factory + +Each filtrator object uses individuals filters which are constructed by a `FilterFactory`. The filtrator depends on the filter factory but if you don't provide it, one will be constructed for your + +```php +use Sirius\Filtration\Filtrator; +use Sirius\Filtration\FilterFactory; + +$filterFactory = new FilterFactory(); +$filtrator = new Filtrator($filterFactory); +``` + +You can register your custom filters within the `FilterFactory` like so: + +```php +$filterFactory->register('my_filter', 'MyApp\Filtration\Filter\MyFilter'); +``` + +If you use dependency injection (and you should) you can have a single filter factory for your entire application and register all the filters you need at the beginning of the app. + +If you don't want to do that you can always pass the class to the filtrator: + +```php +$filtrator->add('content', 'MyApp\Filtration\Filter\MyFilter'); +``` + +Also, if your filters are very complex, that is they have dependencies) you need to extend the filter factory. + +```php +namespace MyApp\Filtration; + +class FilterFactory extends Sirius\Filtration\FilterFactory { + + $protected $container = $container; + + function __construct(Container $container) { + $this->container = $container; + } + + function createFilter($callbackOrFilterName, $options = null, $resursive = false) { + $filter = $this->container->get($callbackOrFilterName, [$options, $recursive]); + if (!$filter) { + $filter = parent::createFilter($callbackOrFilterName, $options, $resursive) + } + return $filter; + } + +} +``` + +Or something to that extent. \ No newline at end of file diff --git a/docs/filters.md b/docs/filters.md index 4222bca..664fd08 100644 --- a/docs/filters.md +++ b/docs/filters.md @@ -6,8 +6,8 @@ Allows using any function, closure or callback for filtering data. The callback Options: -- callback: the function/closure/callback that will be used as filter -- arguments: additional arguments for the callback +- `callback`: the function/closure/callback that will be used as filter +- `arguments`: additional arguments for the callback ## Censor @@ -15,10 +15,10 @@ Obfuscates certain words from a string Options: -- start_characters: leaves untouched this number of characters from the begining of the filtered string. Default: 1 -- start_characters: leaves untouched this number of characters from the end of the filtered string. Default: 1 -- replacement_char: the character that will be used to replace the hidden chars. Default: * -- word: list of words that are censored. Default: look in the source file +- `start_characters`: leaves untouched this number of characters from the begining of the filtered string. Default: 1 +- `start_characters`: leaves untouched this number of characters from the end of the filtered string. Default: 1 +- `replacement_char`: the character that will be used to replace the hidden chars. Default: * +- `word`: list of words that are censored. Default: look in the source file ## CleanArray @@ -26,7 +26,7 @@ Removes null elements from an array. If the array is associative it preserves th Options: -- nullify: whether to use the Nullify filter to convert certain values into NULLs. Default: TRUE +- `nullify`: whether to use the Nullify filter to convert certain values into NULLs. Default: TRUE ## Double @@ -34,7 +34,7 @@ Convert numbers to `double` using a specified precision Options: -- precision: number of digits that the filtered value will have. Default: 2 +- `precision`: number of digits that the filtered value will have. Default: 2 ## Integer @@ -47,8 +47,8 @@ Example: `12/10/2012` to `2012-12-10` Options: -- input_format: the date format in which the value should have been provided. Default: `d/m/Y` -- output_format: the format in which the value is returned. Default: `Y-m-d` +- `input_format`: the date format in which the value should have been provided. Default: `d/m/Y` +- `output_format`: the format in which the value is returned. Default: `Y-m-d` ## NormalizeNumber @@ -57,8 +57,8 @@ Example: `1 234,5` to `1234.5` Options: -- thousands_separator. Default: `.` -- decimal_point. Default: `,` +- `thousands_separator`. Default: `.` +- `decimal_point`. Default: `,` ## Nullify @@ -66,8 +66,8 @@ Converts certain values to NULL Options: -- empty_string: converts empty strings to NULL. Default: TRUE -- zero: converts zero numbers to NULL. Default: TRUE +- `empty_string`: converts empty strings to NULL. Default: TRUE +- `zero`: converts zero numbers to NULL. Default: TRUE ## Obfuscate @@ -75,18 +75,18 @@ Hides certain characters from a string Options: -- start_characters: leaves untouched this number of characters from the begining of the filtered string. Default: 0 -- start_characters: leaves untouched this number of characters from the end of the filtered string. Default: 0 -- replacement_char: the character that will be used to replace the hidden chars. Default: * +- `start_characters`: leaves untouched this number of characters from the begining of the filtered string. Default: 0 +- `start_characters`: leaves untouched this number of characters from the end of the filtered string. Default: 0 +- `replacement_char`: the character that will be used to replace the hidden chars. Default: * ## StringTrim -Removes whitespace at the begining and/or end of strings: +Removes whitespace at the beginning and/or end of strings: Options: -- side: where the string will be trimmed. Possible values: `left`|`right`|`both`. Default: `both`. -- characters: list of characters that will be trimmed. Default: `\t\n\r ` +- `side`: where the string will be trimmed. Possible values: `left`|`right`|`both`. Default: `both`. +- `characters`: list of characters that will be trimmed. Default: `\t\n\r ` ## Truncate @@ -94,6 +94,6 @@ Truncates a string to a maximum number of characters Options: -- limit: max limit of the returned string. Default: FALSE. -- break_words: whether or not breaking a word is a allowed: Default: TRUE -- ellipsis: character added at the end when the string is truncated. Default: ... +- `limit`: max limit of the returned string. Default: FALSE. +- `break_words`: whether or not breaking a word is a allowed: Default: TRUE +- `ellipsis`: character added at the end when the string is truncated. Default: ... diff --git a/docs/index.md b/docs/index.md index 7be7d10..0e5c32f 100755 --- a/docs/index.md +++ b/docs/index.md @@ -1,23 +1,63 @@ -# How to use SiriusFiltration +Sirius Filtration + +[![Source Code](http://img.shields.io/badge/source-siriusphp/filtration-blue.svg?style=flat-square)](https://github.com/siriusphp/filtration) +[![Latest Version](https://img.shields.io/packagist/v/siriusphp/filtration.svg?style=flat-square)](https://github.com/siriusphp/filtration/releases) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/siriusphp/filtration/blob/master/LICENSE) +[![Build Status](https://img.shields.io/travis/siriusphp/filtration/master.svg?style=flat-square)](https://travis-ci.org/siriusphp/filtration) +[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/siriusphp/filtration.svg?style=flat-square)](https://scrutinizer-ci.com/g/siriusphp/filtration/code-structure) +[![Quality Score](https://img.shields.io/scrutinizer/g/siriusphp/filtration.svg?style=flat-square)](https://scrutinizer-ci.com/g/siriusphp/filtration) + +PHP library for array filtering/sanitization + +Sometimes you want to make sure the values pushed by a source (eg: a user when submits a form) follow some restrictions like + +- no space at the beginning or the end for the title of a page +- no HTML code in a comment sent by a user +- no spaces in the field which represents the URL +- remove XSS attacks +- etc... + +Other times you want to make sure that the data you send to the user is parsed before displaying. For example you may want to: + +- convert markdown into HTML +- convert URLs into links +- apply a localized format to dates +- etc () + +To achieve this end result you need to filter the values. This is where SiriusFiltration comes into place + +## Elevator pitch ```php -require_once ('path/to/siriusfiltration/autoload.php'); +use Sirius\Filtration\Filtrator; -$filtrator = new Sirius\Filtration\Filtrator; +$filtrator = new Filtrator(); -// syntax for adding filters -$filtrator->add($selector, $callbackOrFilterName, $options = null, $recursive = false, $priority = 0); +// add filters for title +$filtrator->add('title', 'trim'); +$filtrator->add('title', 'strip_tags'); +$filtrator->add('title', 'nullify'); -// strip all but the P, DIV and BR tags from the content -$filtrator->add('content', 'strip_tags', array('



')); +// add filters for content in one go +$filtrator->add('content', [ + 'trim' +]); -// trim all the elements of the array, only on the first level -$filtrator->add('*', 'trim'); +$result = $filtrator->filter(array( + 'title' => '

My title has tags and is awesome

', + 'content' => ' My content was trimmed' +)); -// trim all the elements of the array, recursively -$filtrator->add('*', 'trim', null, true); +/* $result is +array( + 'title' => NULL , + 'content' => 'My content was trimmed' +) +*/ +``` + +# How to use SiriusFiltration -$filteredPostData = $filtrator->filter($_POST); ``` ### The `$callbackOrFilterName` parameter can be: diff --git a/docs/installation.md b/docs/installation.md new file mode 100644 index 0000000..af51b8f --- /dev/null +++ b/docs/installation.md @@ -0,0 +1,21 @@ +--- +title: Installating Sirius\Filtration +--- + +#Installation + +## Using composer + +Sirius\Validation is available on [Packagist](https://packagist.org/packages/siriusphp/filtration) so you can use +``` +composer require sirius/filtration +``` + +Make sure to include the Composer autoload file in your project +```php +require 'vendor/autoload.php'; +``` + +## Downloading a `.zip` file + +This project is also available for download as a `.zip` file on GitHub. Visit the [releases page](https://github.com/siriusphp/filtration/releases), select the version you want, and click the "Source code (zip)" download button. \ No newline at end of file diff --git a/docs/modeling.md b/docs/model_filtration.md similarity index 90% rename from docs/modeling.md rename to docs/model_filtration.md index 693c62a..783ecff 100644 --- a/docs/modeling.md +++ b/docs/model_filtration.md @@ -1,4 +1,8 @@ -# Using SiriusFiltration for your models +--- +title: Using Sirius\Filtration for models +--- + +# Filtration for your models Usually models are populated with data from a form but that is not always the case. If you use an API you might want to use a filtrator object before populating your models but you can use a filtrator object directly on inside your models. @@ -6,7 +10,6 @@ If you use an API you might want to use a filtrator object before populating you Below is a simple example on how you might use the filtrator with your models ```php - class Customer { protected $filtrator; @@ -33,9 +36,11 @@ class Customer { return $this; } } +``` -// somewhere in your app +somewhere in your app +```php $customer = new Customer(); $customer->setName(' My Name '); // converted to 'My Name' $customer->setBirtdate('20/11/2013'); // converted to '2013-11-20' diff --git a/docs/other.md b/docs/other.md deleted file mode 100644 index 7ef1dac..0000000 --- a/docs/other.md +++ /dev/null @@ -1,54 +0,0 @@ -# Other uses of SiriusFiltration - -## Output filtering - -Most of the times, filters are used to sanitize incoming data but filters are just a way to convert alter data. -There are situations when the data that is stored by your app must be displayed in a different way; dates might be localized, article content might be truncated etc. -If your application is pluggable you might also want to allow other developers to inject their own filters - -Below is a simple example on how you might use the filtrator with your data for output. - -```php - -class ArticleWrapper { - protected $filtrator; - - protected $article; - - function __construct($article, $filtrator) { - $this->article = $arcticle; - $this->filtrator = $filtrator; - } - - function __get($name) { - return $this->filtrator->filterItem($article->{$name}, $name); - } - -} - -// somewhere in your app - -$article = ArticleTable::getById(10); -$articleWrapper = new ArticleWrapper($article, Registry::get('article_filtrator')); - -// anywhere within your plugins/modules -// assuming 'uppercase' and 'truncate' were registered as filters -Registry::get('article_filtrator')->add('title', 'uppercase'); -Registry::get('article_filtrator')->add('title', 'truncate', array('length' => 15)); - -// in your views -echo $articleWrapper->title; // will print 'This Is The Best...' for an article that has the title 'This is the best filter library' -``` - -## Single value filtering - -You may find yourself in a situation when you need to filter a single value (be it a string, number or an object), that is to alter a piece of data according to some rules. -For example, your CMS is displaying the content of an article which may have Markdown formatting and you don't want to employ a filter on the `ArticleWrapper` example above. You could "fake" the array like so - -```php -$filtrator->add('random_key', $filter_you_want_to_be_applied); -$result = $filtrator->filter(array('random_key' => $value_that_you_want_filtrated)); -return $result['random_key']; -``` - -Or you may create a `SingleValueFiltrator` class which simplifies the whole process. diff --git a/docs/output_filtration.md b/docs/output_filtration.md new file mode 100644 index 0000000..dcfbab5 --- /dev/null +++ b/docs/output_filtration.md @@ -0,0 +1,47 @@ +--- +title: Using Sirius\Filtration for output +--- + +# Output filtering + +Most of the times, filters are used to sanitize incoming data but filters are just a way to convert/alter data. +There are situations when the data that is stored by your app must be displayed in a different way; dates might be localized, article content might be truncated etc. +If your application is pluggable you might also want to allow other developers to inject their own filters + +Below is a simple example on how you might use the filtrator with your data for output. + +```php + +class ArticleWrapper { + protected $filtrator; + + protected $article; + + function __construct($article, $filtrator) { + $this->article = $arcticle; + $this->filtrator = $filtrator; + } + + function __get($name) { + return $this->filtrator->filterItem($article->{$name}, $name); + } + +} +``` + +somewhere in your app + +```php +$article = ArticleTable::getById(10); +$filtrator = new Sirius\Filtration\Filtrator; +$filtrator->add('title', 'ucwords'); +$filtrator->add('title', 'truncate', array('length' => 15)); + +$articleWrapper = new ArticleWrapper($article, $filtrator); +``` + +and in your views + +```php +echo $articleWrapper->title; // will print 'This Is The Best...' for an article that has the title 'This is the best filter library' +``` \ No newline at end of file diff --git a/docs/simple_example.md b/docs/simple_example.md new file mode 100644 index 0000000..a9dfa81 --- /dev/null +++ b/docs/simple_example.md @@ -0,0 +1,36 @@ +--- +title: Simple filtration example +--- + +# Simple example + +Let's assume the data you want to filter comes from a form that represents a blog post + + +### Initialize the filtrator object + +```php +require_once ('path/to/siriusfiltration/autoload.php'); + +$filtrator = new Sirius\Filtration\Filtrator; + +// trim all the whitespace from input +$filtrator->add('*', + 'trim' /* the function trim() will be applied to everything */, + null /* additional parameters for the filter */, + true /* recursively apply the filter */, + 100 /* the priority of the filter if you don't want to use the order they are added*/); + +// strip the tags from the blog title +$filtrator->add('title', 'strip_tags'); + +// strip all but the P, DIV and BR tags from the content +$filtrator->add('content', 'strip_tags', array('



')); +``` + +### Get access to the clean data + +```php +$filteredPostData = $filtrator->filter($_POST); +``` + diff --git a/docs/special_selectors.md b/docs/special_selectors.md new file mode 100644 index 0000000..18efd92 --- /dev/null +++ b/docs/special_selectors.md @@ -0,0 +1,42 @@ +--- +title: Syntactic sugar +--- + +# Special data selectors + + +### The `any` selector + +The `Sirius\Filtration` library manipulates the data within arrays and sometimes you apply some filters to all elements of the array. For example you many not want to allow users to provide a space character on some fields (to bypass the 'required' validation rule). + +In this case you do something like this: + +```php +$filtrator->add('*', 'stringtrim | nullify') +``` + +### The `root` selector + +Sometimes you want to be able to alter the entire dataset the user sent to your app. For example, let's say you have a form where a date element is split into 3 input fields (year, month, day) that also have a different name but you want your app to work with a single field. + +In this case you do something like this: +```php +function convertDateArrays($value, $options, $valueIdentifier, $context) { + // here $value will be the entire dataset + $value['date'] = sprintf('%s-%s-%s', $value['__date']['year'], $value['__date']['month'], $value['__date']['day']); + unset($value['__date']); +} + +$filtrator->add('/', 'convertDateArrays'); + +$result = $filtrator->filter(array( + '__date' => array('year'=> 2000, 'month' => 10, 'day' => 5), +)); + +// $result will be +// array( +// 'date' => '2000-10-5' +// ) +``` + +**Important!** The `root` filters are applied first so you can also use it to globally clean all of your data \ No newline at end of file diff --git a/docs/syntactic_sugar.md b/docs/syntactic_sugar.md new file mode 100644 index 0000000..29ebb27 --- /dev/null +++ b/docs/syntactic_sugar.md @@ -0,0 +1,54 @@ +--- +title: Syntactic sugar +--- + +# Syntactic sugar + + +##### 1. Add multiple rules at once by using just a string +```php +// separate rules using ' | ' (space, pipe, space) +$filtrator->add('email', 'stringtrim | nullify'); +``` + +##### 2. Add rule with parameters +```php +// or parameters set as query string +$filtrator->add('name', 'stringtrim(side=both)'); +// parameters set as JSON string, recursive, priority = 10 +$filtrator->add('paragraphs', 'stringrim({"side":"both"})(true)(10)'); + +// the above example is similar to +$filtrator->add('name', 'stringtrim', array('side' => 'both'), true, 10); +``` + +**Important!** You cannot have something like `(this)` inside the JSON or query string. + +##### 3. Mix and match 1 and 2 +```php +$filtrator->add('name', 'stringtrim(side=both) | nullify'); +``` + +**Important!** The sequence ` | ` cannot be inside the parameters. + +##### 4. Add multiple rules per selector +```php +$filtrator->add( + // add the label after the selector so you don't have to pass the label to every rule + 'name', + array( + 'stringtrim', + 'nullify' + ) +); +``` + +##### 5. Add multiple rules on multiple selectors +Mix and match everthing from above +```php +$filtrator->add(array( + 'title' => 'stringtrim | strip_tags | nullify', + 'content' => 'stringtrim | nullify'), + ) +)); +``` \ No newline at end of file