dev-master
9999999-dev https://github.com/djordje/li3_validatorsCollection of lithium validators
BSD-3-Clause
The Requires
- php >=5.3
- composer/installers dev-master
php validators lithium li3
Collection of lithium validators
Git clone:, (*1)
cd path/to/libraries git clone git://github.com/djordje/li3_validators.git
Or trough composer:, (*2)
Add this to your composer.json
file:, (*3)
{ "minimum-stability": "dev", "require": { "djordje/li3_validators": "dev-master" } }
After either of these two steps open app/config/bootstrap/libraries.php
with your editor and add
this to bootom of the file:, (*4)
Libraries::add('li3_validators')
, (*5)
Now you can use this validators in your model just as any other bundled or added validator!, (*6)
Name: 'unique'
, (*7)
Ensure that entered value is unique in database. If 'events'
is update do query with provided options, (*8)
Options:, (*9)
'key'
string - Database table key that will be used as condition key if 'events'
is update, by default 'id'
, (*10)
'keyValue'
string - Setup key value if you don't want to fetch it from 'values'
field, by default null
which means that field fetch value of $options['values']['id']
if you don't change 'key'
, (*11)
Name: 'confirm'
, (*12)
Confirm that this field is equal to field against we compare., (*13)
Options:, (*14)
'strategy'
string (direct|password) - Default is 'direct'
which means we compare value against
desired field directly 'string' === 'string'
. If we set this to 'password'
validator use
Password::check()
for comparing value against desired field, (*15)
'against'
string - By default this is null
which means we will compare this field against same
named field with confirm_
prefix, eg. email
against confirm_email
, or we can set field name
against we want to compare, (*16)
Name: 'dependencies'
, (*17)
Check field dependencies. Evaluate conditions to see if all dependencies are correct, (*18)
Options:, (*19)
'conditions'
array - Eval comparation builder compatible conditions array, (*20)
Example:, (*21)
$options = array('conditions' => array( array('gender', '===', 'M') ));
This field will require 'gender'
field equal to 'M'
, (*22)
Name: 'compareWithOldDbValue'
, (*23)
Compare value with existing value in database, (*24)
Options:, (*25)
'strategy'
string (direct|password) - Default is 'direct'
which means we compare value against
desired field directly 'string' === 'string'
. If we set this to 'password'
validator use
Password::check()
for comparing value against desired field, (*26)
'findBy'
string - Field name that will be used as condition for finding original value, default is 'id'
, (*27)
'field'
string - Original field name, (*28)
Example:, (*29)
$options = array( 'strategy' => 'password', 'field' => 'password' );
This validator will assume that value of this field, for example 'old_password'
is equal to the
value of 'password'
field where 'id'
is equal to current 'id'
, (*30)
Name: 'condtionalInRange'
, (*31)
This validator is very similar to Lithium's 'inRange'
validator, but require conditions to be true
as well, (*32)
Options:, (*33)
'upper'
integer, (*34)
'lower'
integer, (*35)
'conditions'
array - Eval comparation builder compatible conditions array, (*36)
Example:, (*37)
$options = array( 'lower' => 169, 'upper' => '206', 'conditions' => array( array('gender', '===', 'M') ) );
This assume that value of this field (for example 'height'
) is greater than 169 and smaller than
206 just if 'gender'
field exists and is equal to 'M'
, (*38)
Name: 'email'
, (*39)
Options:, (*40)
'pattern'
mixed (false|regex) - If false
use php filter_var()
function (default in Lithium)
to check value, or regex
to match against., (*41)
'mx'
boolean that enable validator to check if MX DNS record exists, (*42)
You can achieve lithium's default behavior with options 'mx' => false, 'pattern' => false
., (*43)
By default this filter check against custom regex that doesn't match all
RFC 5322 valid emails, but will match against most correct
emails, and doesn't check domain against MX DNS record.
'mx' => false, 'pattern' => '/^[a-z0-9][a-z0-9_.-]*@[a-z0-9.-]{3,}\.[a-z]{2,4}$/i'
, (*44)
li3_validators\extensions\util\EvalComparation::build(array $options)
, (*45)
Options:, (*46)
conditions
array - This array will be converted to eval string, (*47)
values
array - Associative array of values that will be used in generated condition, (*48)
Best way to understand this utility method is example:, (*49)
$options = array( 'conditions' => array(array('name', '===', 'diff_test_name')), 'values' => array('name' => 'test_name') ); $eval_one = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name'));' $options = array( 'conditions' => array( array('name', '===', 'diff_test_name'), '||', array('name', '===', 'test_name') ), 'values' => array('name' => 'test_name') ); $eval_two = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name') || ('test_name' === 'test_name'));'
eval($eval_one)
will evaluate false
, (*50)
eval($eval_two)
will evaluate true
, (*51)
You can build nested conditions as well:, (*52)
$options = array( 'conditions' => array( array('name', '===', 'diff_test_name'), '&&', array( array('other_field', '===', null), '||', array('other_field', '===', 'correct') ) ), 'values' => array('name' => 'test_name', 'other_field' => 'other_field_val') ); $eval_tree = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name') && (('other_field_val' === null) || ('other_field_val' === 'correct')));'
[]
(https://travis-ci.org/djordje/li3_validators)
[
]
(http://stillmaintained.com/djordje/li3_validators), (*53)
Collection of lithium validators
BSD-3-Clause
php validators lithium li3