Class RuleInvoker
Contains logic for invoking an application rule.
Combined with {@link \Cake\Datasource\RulesChecker} as an implementation detail to de-duplicate rule decoration and provide cleaner separation of duties.
Property Summary
Method Summary
-
__construct() public
Constructor
-
__invoke() public
Invoke the rule.
-
setName() public
Set the rule name.
-
setOptions() public
Set options for the rule invocation.
Method Detail
__construct() ¶ public
__construct(callable $rule, string|null $name, array<string, mixed> $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|null
$name The name of the rule. Used in error messages.
-
array<string, mixed>
$options optional The options for the rule. See above.
__invoke() ¶ public
__invoke(Cake\Datasource\EntityInterface $entity, array $scope): bool
Invoke the rule.
Parameters
-
Cake\Datasource\EntityInterface
$entity The entity the rule should apply to.
-
array
$scope The rule's scope/options.
Returns
bool
setName() ¶ public
setName(string|null $name): $this
Set the rule name.
Only truthy names will be set.
Parameters
-
string|null
$name The name to set.
Returns
$this
setOptions() ¶ public
setOptions(array<string, mixed> $options): $this
Set options for the rule invocation.
Old options will be merged with the new ones.
Parameters
-
array<string, mixed>
$options The options to set.
Returns
$this