Contains logic for storing and checking rules on entities
RulesCheckers are used by Table classes to ensure that the current entity state satisfies the application logic and business rules.
RulesCheckers afford different rules to be applied in the create and update scenario.
Rules must be callable objects that return true/false depending on whether or not the rule has been satisfied. You can use RulesChecker::add(), RulesChecker::addCreate(), RulesChecker::addUpdate() and RulesChecker::addDelete to add rules to a checker.
Generally a Table object will invoke the rules objects, but you can manually invoke the checks by calling RulesChecker::checkCreate(), RulesChecker::checkUpdate() or RulesChecker::checkDelete().
__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
string | CREATE Indicates that the checking rules to apply are those used for creating entities | 'create' |
string | DELETE Indicates that the checking rules to apply are those used for deleting entities | 'delete' |
string | UPDATE Indicates that the checking rules to apply are those used for updating entities | 'update' |
© 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.Datasource.RulesChecker.html