ORM flavoured rules checker.
Adds ORM related features to the RulesChecker class.
existsIn( string|array $field , object|string $table , string $message null )
Returns a callable that can be used as a rule for checking that the values extracted from the entity to check exist as the primary key in another table.
This is useful for enforcing foreign key integrity checks.
$rules->add($rules->existsIn('author_id', 'Authors', 'Invalid Author')); $rules->add($rules->existsIn('site_id', new SitesTable(), 'Invalid Site'));
$field
$table
$message
optional null callable
isUnique( array $fields , string $message null )
Returns a callable that can be used as a rule for checking the uniqueness of a value in the table.
$rules->add($rules->isUnique(['email'], 'The email should be unique'));
$fields
$message
optional null callable
__construct( array $options [] )
Constructor. Takes the options to be passed to all rules.
$options
optional [] _addError( callable $rule , string $name , array $options )
Utility method for decorating any callable so that if it returns false, the correct property in the entity is marked as invalid.
$rule
$name
$options
callable
_checkRules( Cake\Datasource\EntityInterface $entity , array $options [] , array $rules [] )
Used by top level functions checkDelete, checkCreate and checkUpdate, this function iterates an array containing the rules to be checked and checks them all.
Cake\Datasource\EntityInterface
$entity
$options
optional [] $rules
optional [] boolean
add( callable $rule , string $name null , array $options [] )
Adds a rule that will be applied to the entity both on create and update operations.
The options array accept the following special keys:
errorField
: The name of the entity field that will be marked as invalid if the rule does not pass.message
: The error message to set to errorField
if the rule does not pass.$rule
$name
optional null $options
optional [] mixed
addCreate( callable $rule , string $name null , array $options [] )
Adds a rule that will be applied to the entity on create operations.
The options array accept the following special keys:
errorField
: The name of the entity field that will be marked as invalid if the rule does not pass.message
: The error message to set to errorField
if the rule does not pass.$rule
$name
optional null $options
optional [] mixed
addDelete( callable $rule , string $name null , array $options [] )
Adds a rule that will be applied to the entity on delete operations.
The options array accept the following special keys:
errorField
: The name of the entity field that will be marked as invalid if the rule does not pass.message
: The error message to set to errorField
if the rule does not pass.$rule
$name
optional null $options
optional [] mixed
addUpdate( callable $rule , string $name null , array $options [] )
Adds a rule that will be applied to the entity on update operations.
The options array accept the following special keys:
errorField
: The name of the entity field that will be marked as invalid if the rule does not pass.message
: The error message to set to errorField
if the rule does not pass.$rule
$name
optional null $options
optional [] mixed
check( Cake\Datasource\EntityInterface $entity , string $mode , array $options [] )
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules to be applied are depended on the $mode parameter which can only be RulesChecker::CREATE, RulesChecker::UPDATE or RulesChecker::DELETE
Cake\Datasource\EntityInterface
$entity
$mode
$options
optional [] boolean
InvalidArgumentException
checkCreate( Cake\Datasource\EntityInterface $entity , array $options [] )
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules selected will be only those specified to be run on 'create'
Cake\Datasource\EntityInterface
$entity
$options
optional [] boolean
checkDelete( Cake\Datasource\EntityInterface $entity , array $options [] )
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules selected will be only those specified to be run on 'delete'
Cake\Datasource\EntityInterface
$entity
$options
optional [] boolean
checkUpdate( Cake\Datasource\EntityInterface $entity , array $options [] )
Runs each of the rules by passing the provided entity and returns true if all of them pass. The rules selected will be only those specified to be run on 'update'
Cake\Datasource\EntityInterface
$entity
$options
optional [] boolean
CREATE, DELETE, UPDATE |
protected array
The list of rules to be checked on both create and update operations
[]
protected boolean
Whether or not to use I18n functions for translating default error messages
false
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.1/class-Cake.ORM.RulesChecker.html