Download the PHP package whatdafox/sanitizer without Composer
On this page you can find all versions of the php package whatdafox/sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download whatdafox/sanitizer
More information about whatdafox/sanitizer
Files in whatdafox/sanitizer
Package sanitizer
Short Description Simple sanitizer class for PHP
License MIT
Homepage https://github.com/WhatDaFox/Sanitizer
Informations about the package sanitizer
Sanitizr
Basic sanitizer class for PHP applications.
Features
Sanitize an array of data to any set of rules.
Methods
- All php text methods
- Custom methods
If you think about anything else that could be added, feel free to submit a PR on the develop branch.
Install
Install this package through composer
Create a class that extends Sanitizer\Sanitizer
and create a property rules
to indicate your rules
To use your sanitizer, just call the sanitize()
method with the array of data like so:
Custom sanitizers
If you would like to create your own sanitizing methods, just create a method with the sanitize
prefix on your class like so:
Then add snakeCase
anywhere in your rules to use it!
Use with Laravel
You can inject any Sanitizer class you will create as a dependency within a constructor or in a method in your Laravel controllers.
Just typehint the class like so:
You can also call the sanitize method automatically when Laravel is resolving the dependency, by using Container Events in your Service Providers. For example:
This example will apply the rules to the request data when resolving the injected sanitizer class, this way you do not have to call sanitize()
yourself!
That's all folks!
Thanks
Thanks for Jeffrey Way and Laracasts for the inspiration and examples. http://laracasts.com