Fr3nch13/CakePHP Utilities

ExistsIn
in package

Checks that the value provided in a field exists as the primary key of another table.

Table of Contents

Properties

$_fields  : array<string|int, string>
The list of fields to check
$_options  : array<string, mixed>
Options for the constructor
$_repository  : Table|Association|string
The repository where the field will be looked for

Methods

__construct()  : mixed
Constructor.
__invoke()  : bool
Performs the existence check
_fieldsAreNull()  : bool
Checks whether the given entity fields are nullable and null.

Properties

$_fields

The list of fields to check

protected array<string|int, string> $_fields

$_options

Options for the constructor

protected array<string, mixed> $_options = []

Methods

__construct()

Constructor.

public __construct(array<string|int, string>|string $fields, Table|Association|string $repository[, array<string, mixed> $options = [] ]) : mixed

Available option for $options is 'allowNullableNulls' flag. Set to true to accept composite foreign keys where one or more nullable columns are null.

Parameters
$fields : array<string|int, string>|string

The field or fields to check existence as primary key.

$repository : Table|Association|string

The repository where the field will be looked for, or the association name for the repository.

$options : array<string, mixed> = []

The options that modify the rule's behavior. Options 'allowNullableNulls' will make the rule pass if given foreign keys are set to null. Notice: allowNullableNulls cannot pass by database columns set to NOT NULL.

__invoke()

Performs the existence check

public __invoke(EntityInterface $entity, array<string, mixed> $options) : bool
Parameters
$entity : EntityInterface

The entity from where to extract the fields

$options : array<string, mixed>

Options passed to the check, where the repository key is required.

Tags
throws
RuntimeException

When the rule refers to an undefined association.

Return values
bool

_fieldsAreNull()

Checks whether the given entity fields are nullable and null.

protected _fieldsAreNull(EntityInterface $entity, Table $source) : bool
Parameters
$entity : EntityInterface

The entity to check.

$source : Table

The table to use schema from.

Return values
bool

        
On this page

Search results