Class RuleInvoker

Contains logic for invoking an application rule.

Combined with Cake\Datasource\RuleChecker as an implementation detail to de-duplicate rule decoration and provide cleaner separation of duties.

Namespace: Cake\Datasource

Properties summary

  • $name protected
    string|null

    The rule name

  • $options protected
    array

    Rule options

  • $rule protected
    callable

    Rule callable

Method Summary

Method Detail

__construct() public

__construct(callable $rule, ?string $name, array $options)

Constructor

Options

  • errorField The field errors should be set onto.
  • message The error message.

Individual rules may have additional options that can be set here. Any options will be passed into the rule as part of the rule $scope.

Parameters

callable $rule

The rule to be invoked.

?string $name

The name of the rule. Used in error messsages.

array $options optional

The options for the rule. See above.

__invoke() public

__invoke(\Cake\Datasource\EntityInterface $entity, array $scope)

Invoke the rule.

Parameters

\Cake\Datasource\EntityInterface $entity

The entity the rule should apply to.

array $scope

The rule's scope/options.

Returns

bool

Whether or not the rule passed.

setName() public

setName(?string $name)

Set the rule name.

Only truthy names will be set.

Parameters

string|null $name

The name to set.

Returns

$this

setOptions() public

setOptions(array $options)

Set options for the rule invocation.

Old options will be merged with the new ones.

Parameters

array $options

The options to set.

Returns

$this

Property Detail

$name protected

The rule name

Type

string|null

$options protected

Rule options

Type

array

$rule protected

Rule callable

Type

callable

© 2005–present 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.
https://api.cakephp.org/4.0/class-Cake.Datasource.RuleInvoker.html