italystrap / cleaner
Data cleaner for PHP
1.2.0
2019-12-27 12:37 UTC
Requires
- php: >=7.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.5.0
- italystrap/debug: ~2.0
- lucatume/function-mocker-le: ^1.0
- lucatume/wp-browser: ~2.2
- phpcompatibility/php-compatibility: *
- phpstan/phpstan: ^0.11.16
- szepeviktor/phpstan-wordpress: ^0.3.0
- wp-coding-standards/wpcs: ^2.1
This package is auto-updated.
Last update: 2024-10-27 23:06:09 UTC
README
PHP Sanitizer and Validation OOP way
Table Of Contents
Installation
The best way to use this package is through Composer:
composer require italystrap/cleaner
Basic Usage
$sanitizator = new \ItalyStrap\Cleaner\Sanitization(); $validator = new \ItalyStrap\Cleaner\Validation(); $sanitizator->addRules( 'trim' ); // `Test` echo $sanitizator->sanitize( ' Test ' ); // Single string rule $rule = 'trim'; $sanitizator->addRules( $rule ); // `Test` echo $sanitizator->sanitize( ' Test ' ); // Multiple rules in string $rules = 'strip_tags|trim'; $sanitizator->addRules( $rules ); // `Test` echo $sanitizator->sanitize( ' <p> Test </p> ' ); // Multiple rules string in array $rules_arr = [ 'strip_tags', 'trim', ]; $sanitizator->addRules( $rules_arr ); // `Test` echo $sanitizator->sanitize( ' <p> Test </p> ' ); $callback = function ( $value ) { return 'New value from callback'; }; // Callable rule in array $rule_callable = [ $callback ]; $sanitizator->addRules( $rule_callable ); // `New value from callback` echo $sanitizator->sanitize( ' <p> Test </p> ' ); // Multiple callable rules in array $rules_callable = [ $callback, $callback, ]; $sanitizator->addRules( $rules_callable ); // `New value from callback` echo $sanitizator->sanitize( ' <p> Test </p> ' );
Every ::sanitize() or ::validate() call will reset the rules provided. Make sure you provide new rule befor calling ::sanitize() or ::validate().
Advanced Usage
TODO
Contributing
All feedback / bug reports / pull requests are welcome.
License
Copyright (c) 2019 Enea Overclokk, ItalyStrap
This code is licensed under the MIT.
Credits
TODO