dgifford / filter
Class for filtering, validating and sanitizing data.
v3.6
2017-03-07 16:36 UTC
Requires
- php: >=5.4
- alcohol/iso4217: 3.1
- dgifford/array-helpers-trait: 1.*
- dgifford/method-calling-trait: 1.*
- egulias/email-validator: 2.1.*
This package is auto-updated.
Last update: 2024-11-14 07:28:37 UTC
README
This class enables you to easily validate and sanitize data using filter definitions.
The filter definitions can be combined to perform a series of validation/ sanitization operations.
Basic Validation Usage
Use dgifford\Filter\Validator;
// Valid email
$email = new Validator( 'dude@example.com', 'email' );
var_dump( $email->isValid() ); // true
$email->setValue( 'dude@@@@example.com' );
var_dump( $email->isValid() ); // false
Basic Sanitization Usage
Use dgifford\Filter\Sanitizer;
$email = new Sanitizer( ' dude@example.com ', 'email' );
echo $email->value; // ' dude@example.com '
echo $email->result; // 'dude@example.com'
var_dump( $email->isValid() ); // true
Editing values and filters
Use dgifford\Filter\Validator;
$email = new Validator( 'dude@example.com', 'email' );
$email->setValue( 'wibble@example.com' );
$email->setFilter( 'email_rfc2822' );
$email->set( 'wibble@example.com', 'email_rfc2822' );
Combining filters
Filters are combined by seperating them with a space.
Use dgifford\Filter\Sanitizer;
$email = new Sanitizer( ' dude@example.com ', 'trim email' );
echo $email->result; // 'dude@example.com'
Filter Variables
Some filters can contain variables. This are concatenated to the end of the filter name with the pipe symbol, | .
$email = new Validator( 'dude@example.com', 'email ends_with|@example.com' );
var_dump( $email->isValid() ); // true