CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Association
  • AssociationCollection
  • Behavior
  • BehaviorRegistry
  • EagerLoader
  • Entity
  • Marshaller
  • Query
  • ResultSet
  • RulesChecker
  • SaveOptionsBuilder
  • Table
  • TableRegistry

Interfaces

  • PropertyMarshalInterface

Traits

  • AssociationsNormalizerTrait

Class RulesChecker

ORM flavoured rules checker.

Adds ORM related features to the RulesChecker class.

Cake\Datasource\RulesChecker
Extended by Cake\ORM\RulesChecker
Namespace: Cake\ORM
See: Cake\Datasource\RulesChecker
Location: ORM/RulesChecker.php

Inherited Constants

  • CREATE, DELETE, UPDATE

Inherited Properties

  • _createRules, _deleteRules, _options, _rules, _updateRules, _useI18n

Method Summary

  • existsIn() public

    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.

  • isUnique() public

    Returns a callable that can be used as a rule for checking the uniqueness of a value in the table.

  • validCount() public
    Validates the count of associated records.

Method Detail

existsIn() public ¶

existsIn( string|string[] $field , object|string $table , string|array|null $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.

Example:

$rules->add($rules->existsIn('author_id', 'Authors', 'Invalid Author'));

$rules->add($rules->existsIn('site_id', new SitesTable(), 'Invalid Site'));

Available $options are error 'message' and 'allowNullableNulls' flag. 'message' sets a custom error message. Set 'allowNullableNulls' to true to accept composite foreign keys where one or more nullable columns are null.

Parameters
string|string[] $field

The field or list of fields to check for existence by primary key lookup in the other table.

object|string $table
The table name where the fields existence will be checked.
string|array|null $message optional null

The error message to show in case the rule does not pass. Can also be an array of options. When an array, the 'message' key can be used to provide a message.

Returns
callable

isUnique() public ¶

isUnique( array $fields , string|array|null $message = null )

Returns a callable that can be used as a rule for checking the uniqueness of a value in the table.

Example:

$rules->add($rules->isUnique(['email'], 'The email should be unique'));
Parameters
array $fields
The list of fields to check for uniqueness.
string|array|null $message optional null

The error message to show in case the rule does not pass. Can also be an array of options. When an array, the 'message' key can be used to provide a message.

Returns
callable

validCount() public ¶

validCount( string $field , integer $count = 0 , string $operator = '>' , string|null $message = null )

Validates the count of associated records.

Parameters
string $field
The field to check the count on.
integer $count optional 0
The expected count.
string $operator optional '>'
The operator for the count comparison.
string|null $message optional null
The error message to show in case the rule does not pass.
Returns
callable

Methods inherited from Cake\Datasource\RulesChecker

__construct() public ¶

__construct( array $options = [] )

Constructor. Takes the options to be passed to all rules.

Parameters
array $options optional []
The options to pass to every rule

_addError() protected ¶

_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.

Parameters
callable $rule
The rule to decorate
string $name
The alias for a rule.
array $options
The options containing the error message and field.
Returns
callable

_checkRules() protected ¶

_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.

Parameters
Cake\Datasource\EntityInterface $entity
The entity to check for validity.
array $options optional []
Extra options to pass to checker functions.
array $rules optional []
The list of rules that must be checked.
Returns
boolean

add() public ¶

add( callable $rule , string|null $name = null , array $options = [] )

Adds a rule that will be applied to the entity both on create and update operations.

Options

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.
Parameters
callable $rule

A callable function or object that will return whether the entity is valid or not.

string|null $name optional null
The alias for a rule.
array $options optional []

List of extra options to pass to the rule callable as second argument.

Returns

$this

addCreate() public ¶

addCreate( callable $rule , string|null $name = null , array $options = [] )

Adds a rule that will be applied to the entity on create operations.

Options

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.
Parameters
callable $rule

A callable function or object that will return whether the entity is valid or not.

string|null $name optional null
The alias for a rule.
array $options optional []

List of extra options to pass to the rule callable as second argument.

Returns

$this

addDelete() public ¶

addDelete( callable $rule , string|null $name = null , array $options = [] )

Adds a rule that will be applied to the entity on delete operations.

Options

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.
Parameters
callable $rule

A callable function or object that will return whether the entity is valid or not.

string|null $name optional null
The alias for a rule.
array $options optional []

List of extra options to pass to the rule callable as second argument.

Returns

$this

addUpdate() public ¶

addUpdate( callable $rule , string|null $name = null , array $options = [] )

Adds a rule that will be applied to the entity on update operations.

Options

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.
Parameters
callable $rule

A callable function or object that will return whether the entity is valid or not.

string|null $name optional null
The alias for a rule.
array $options optional []

List of extra options to pass to the rule callable as second argument.

Returns

$this

check() public ¶

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

Parameters
Cake\Datasource\EntityInterface $entity
The entity to check for validity.
string $mode
Either 'create, 'update' or 'delete'.
array $options optional []
Extra options to pass to checker functions.
Returns
boolean
Throws
InvalidArgumentException
if an invalid mode is passed.

checkCreate() public ¶

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'

Parameters
Cake\Datasource\EntityInterface $entity
The entity to check for validity.
array $options optional []
Extra options to pass to checker functions.
Returns
boolean

checkDelete() public ¶

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'

Parameters
Cake\Datasource\EntityInterface $entity
The entity to check for validity.
array $options optional []
Extra options to pass to checker functions.
Returns
boolean

checkUpdate() public ¶

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'

Parameters
Cake\Datasource\EntityInterface $entity
The entity to check for validity.
array $options optional []
Extra options to pass to checker functions.
Returns
boolean
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs