2017 © Pedro Peláez
 

library sanitizer

image

daylerees/sanitizer

  • Monday, July 17, 2017
  • by daylerees
  • Repository
  • 11 Watchers
  • 232 Stars
  • 44,664 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 19 Forks
  • 1 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

Travis Status Github Release Packagist License Packagist Downloads Github Issues Tips, (*1)

Sanitizer Package

Sanitizers can be used to standardize data to ease validation, or provide data consistency., (*2)

Basic Usage

First construct a rules array., (*3)

$rules = [
    'name'      => 'trim',
    'email'     => 'trim|strtolower'
];

Rules can contain either callable functions, or the name of a sanitizer binding (more later). You can use either a pipe | or an array to specify multiple sanitization rules., (*4)

The sanitizer can be executed in the following fashion., (*5)

$sanitizer = new Sanitizer;
$sanitizer->sanitize($rules, $data);

Here's a full example., (*6)

// Construct rules array.
$rules = [
    'name'      => 'trim',
    'email'     => 'trim|strtolower'
];

// Data array to be sanitized.
$data = [
    'name' => ' Dayle ',
    'email' => ' me@DAYLEREES.com'
];

// Construct a new sanitizer.
$sanitizer = new Sanitizer;

// Execute the sanitizer.
$sanitizer->sanitize($rules, $data);

Here's the content of $data after execution., (*7)

[
    'name' => 'Dayle',
    'email' => 'me@daylerees.com'
]

Using the Laravel facade, the syntax can be made a little cleaner., (*8)

Sanitizer::sanitize($rules, $data);

Sanitize a single value like so., (*9)

$rules = 'trim|strtolower';
$data = '  Dayle';

Sanitizer::sanitizeValue($rules, $data);

Here is the value returned., (*10)

dayle

Custom Sanitization Rules

Sanitizers can be added multiple ways., (*11)

Using a Closure.

Sanitizer::register('reverse', function ($field) {
    return strrev($field);
});

Using a Callback.

Sanitizer::register('reverse', [new ClassHere, 'method']);

Using a class/method pair.

Sanitizer::register('reverse', 'Namespace\Class\Here@method');

The class will be resolved through an instance of the Illuminate IoC container, if no method is provided then sanitize() is assumed., (*12)

Installation

The Sanitizer package can be used stand-alone or with the Laravel Framework., (*13)

Stand-alone

First include the sanitizer package., (*14)

"daylerees/sanitizer": "dev-master"

Now simply use the Sanitizer class., (*15)

use Rees\Sanitizer\Sanitizer;

With Laravel

Include the Service Provider class within the app/config/app.php file., (*16)

'providers' => array(
    ...
    'Rees\Sanitizer\SanitizerServiceProvider'
)

Now simply add the facade alias., (*17)

'aliases' => array(
    ...
    'Sanitizer' => 'Rees\Sanitizer\Facade'
)

The Versions

17/07 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

27/09 2014

1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

13/06 2014

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

22/05 2014

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires