Slick Filter is a set of filter utilities tah can be used to filter input values, sanitize data and create filter chains to apply on a certain value.
This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.
Via Composer
$ composer require slick/filter
The best way to filter your data is to use the StaticFilter
utility class. It can create any
FilterInterface
filter and it has alias for the known filters that are bundled with the
Slick\Filter
package.
use Slick\Filter\StaticFilter;
echo StaticFilter::filter('number', '12 3'); // Will output 123
$text = StaticFilter::filter('text', 123);
echo is_string($text); // will output 1 (true)
Alias | Class | Description |
---|---|---|
text | Slick\Filter\Text |
Converts input to a string |
number | Slick\Filter\Number |
Converts the input to an integer number |
url | Slick\Filter\Url |
Converts/Fixes the input to a valid URL |
htmlEntities | Slick\Filter\HtmlEntities |
Converts special characters to its html entity representation |
It is also possible to combine multiple filters to a single input value by using the
FilterChainInterface
.
use Slick\Filter\FilterChain;
use Slick\Filter\StaticFilter;
$filterChain = new FilterChain();
$filterChain
->add(StaticFilter::create('text'))
->add(StaticFilter::create('htmlEntities'));
$input = '<p>This is a simple text & cia!</p>';
$output = $filterChain->filter($value);
echo $output;
The above code will output:
This is a simple text & cia!
You can create you own filters by implementing the FilterInterface
.
$ vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security related issues, please email silvam.filipe@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.