Download the PHP package fadion/sanitizer without Composer

On this page you can find all versions of the php package fadion/sanitizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sanitizer

Input Sanitizer

A standalone input sanitizer with options to easily use it in Laravel's FormRequest. It provides a good selection of sanitizers for most use cases, from trimming and lowercase, to masking and casting.

What's the use you're asking? User input is quite arbitrary! Even with guidelines in place, you can't expect a user to enter the appropriate information in the way you hope them to. Validation makes sure the input format is correct, but it shouldn't stop there. An email may need to be trimmed of whitespace, a name may need to be capitalized, and so on. Instead of doing all that manually, Sanitizer will make it a breeze.

Installation

Laravel users can add the ServiceProvider and Facade for convenience. This step isn't needed for FormRequest.

Usage

You'll need an array of inputs to be sanitized, most probably from a request object or plain POST/GET data. A basic example would be like the following:

The array of sanitizers needs the input name as the key and a list of sanitizers as either an array, or a string separated with a pipe (Laravel's validator style).

Both of these are valid:

For those cases when you need to run some custom code on an input, you can pass a closure as a sanitizer. Don't confuse closure sanitizers with custom sanitizers; these are one-time, anonymous sanitizers that can't be reused. As with the predefined ones, they can be combined with other sanitizers. Take a look at the following code:

A few sanitizers accept arguments, such as date, number_format, limit, mask and int. The syntax is described below:

Usage in Laravel

In Laravel you can directly use the Facade if that's your style. Just remember to include the ServiceProvider and Facade as in the instructions. After that, it's as easy as writing:

Usage in FormRequest

Form requests are, in my opinion, a very good way of writing validation code. In addition to validation, you can use Sanitizer to clean and transform your inputs in a very intuitive way.

You already know how to create a FormRequest and add rules to it. Let's see how to sanitize those inputs:

You'll notice I've used the Sanitizable trait! That's what includes the needed functionality and will enable to define sanitizers. You'll also notice there's a sanitizers() method. Just return an array with the inputs as keys and Sanitizer will do its job automatically.

Custom Sanitizers

For most, the predefined sanitizers are all they'll ever need. However, in some rare occassion you may need to run some specific code more than once and it may come in handy to register it as a custom sanitizer. Just remember that complicated logic doesn't belong to the Sanitizer or a FormRequest. Use these only for simple, trival transformations.

Standalone

Call the static register method anywhere in your code, but before the sanitizer is to be used.

Laravel

The best place to register a custom sanitizer would be in a Service Provider. It can either be a custom, dedicated provider (ie: SanitizerServiceProvider) or in the more general AppServiceProvider. Whatever you choose, write your code inside the boot() method:

The register method accepts a name and a closure. You can register as many custom sanitizers as you need and even override the predefined ones. Now you can use the newly created sanitizer everywhere in your code:

Available Filters

There are more than 30 available filters and most of them use native PHP functions. Refer to the Filters.php file for the whole list. Every method is documented, but the code is pretty straightforward for everyone to understand.


All versions of sanitizer with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fadion/sanitizer contains the following files

Loading the files please wait ....