Validate
- Full name:
\Zemit\Mvc\Model\Traits\Validate
Methods
genericValidation
Apply generic validation to a validator object.
public genericValidation(\Zemit\Filter\Validation|null $validator = null): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | **\Zemit\Filter\Validation | null** |
Return Value:
The validator object with the generic validation rules applied.
addNotEmptyValidation
Add validation to ensure that a field is not empty
public addNotEmptyValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = false): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add the validation to |
$field | **array | string** |
$allowEmpty | bool | Whether to allow empty values. Default is false. |
Return Value:
The updated validation object
addPresenceValidation
Add presence validation to a field in a validator object
public addPresenceValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation to |
$field | **array | string** |
$allowEmpty | bool | Whether to allow empty values for the field or not (default: true) |
Return Value:
The modified validator object after adding the validation
addUnsignedIntValidation
Add validations for an unsigned integer field
public addUnsignedIntValidation(\Zemit\Filter\Validation $validator, array|string $field = 'id', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add rules to |
$field | **array | string** |
$allowEmpty | bool | Whether to allow the field to be empty (default: true) |
Return Value:
The updated validation object with the added rules
addUnsignedBigIntValidation
Add basic validations for the specified field to ensure it is an unsigned big integer
public addUnsignedBigIntValidation(\Zemit\Filter\Validation $validator, array|string $field = 'id', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add rules to |
$field | **array | string** |
$allowEmpty | bool | Whether empty values are allowed or not (default is true) |
Return Value:
The updated validation object
addNumberValidation
Add number validations for a given field
public addNumberValidation(\Zemit\Filter\Validation $validator, array|string $field, int $min, int $max, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add the validations to |
$field | **array | string** |
$min | int | The minimum value allowed for the field |
$max | int | The maximum value allowed for the field |
$allowEmpty | bool | Specifies whether the field can be empty |
Return Value:
The modified validation object with the number validations added
addStringLengthValidation
Add string length validations for a field
public addStringLengthValidation(\Zemit\Filter\Validation $validator, array|string $field, int $minChar, int $maxChar = 255, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add the validations to |
$field | **array | string** |
$minChar | int | The minimum number of characters allowed (default: 0) |
$maxChar | int | The maximum number of characters allowed (default: 255) |
$allowEmpty | bool | Whether empty values are allowed (default: true) |
Return Value:
The validation object with the added validations
addInclusionInValidation
Add inclusion validation for a field
public addInclusionInValidation(\Zemit\Filter\Validation $validator, array|string $field, array $domainList = [], bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object |
$field | **array | string** |
$domainList | array | The list of valid values for the field |
$allowEmpty | bool | Set to true to allow empty values (default: true) |
Return Value:
The updated validation object with the inclusion validation added
addBooleanValidation
Add basic validations for a boolean field - Must not be empty - Must be a boolean value (1, 0, true, false)
public addBooleanValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add the validations to |
$field | **array | string** |
$allowEmpty | bool | Whether to allow empty values or not (default: true) |
Return Value:
The updated validation object
addInclusionValidation
Add inclusion validation for a specified field
public addInclusionValidation(\Zemit\Filter\Validation $validator, array|string $field, array $domain = [], bool $allowEmpty = true, bool $strict = true): \Zemit\Filter\Validation
This method adds an inclusion validation rule to the given validator object for the specified field. The inclusion rule checks if the value of the field is included in the specified domain.
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to which the rule should be added |
$field | **array | string** |
$domain | array | The array of allowed values for the field |
$allowEmpty | bool | Whether to allow empty values for the field (default: true) |
$strict | bool | Whether to use strict comparison for checking inclusion (default: true) |
Return Value:
The updated validator object
addUniquenessValidation
Add uniqueness validation for the specified field(s)
public addUniquenessValidation(\Zemit\Filter\Validation $validator, string|array $field, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add the validation rules to |
$field | **string | array** |
$allowEmpty | bool | Whether to allow empty values for the field(s) |
Return Value:
The modified validation object
addEmailValidation
Add email validation to a field
public addEmailValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object |
$field | **array | string** |
$allowEmpty | bool | Whether to allow empty values for the field (default: true) |
Return Value:
The modified validator object
addDateValidation
Add basic validations for the date field - Must not be empty - Must be a valid date in the specified format
public addDateValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true, string $format = Column::DATE_FORMAT): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add the validations to |
$field | **array | string** |
$allowEmpty | bool | Whether to allow empty values for the date field (default: true) |
$format | string | The expected format of the date field (default: Column::DATE_FORMAT) |
Return Value:
The updated validation object
addDateTimeValidation
Add basic validations for the datetime field - Must not be empty - Must be a valid datetime format
public addDateTimeValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true, string $format = Column::DATETIME_FORMAT): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object |
$field | **array | string** |
$allowEmpty | bool | Specifies if the field is allowed to be empty (default: true) |
$format | string | The format of the datetime (default: Column::DATETIME_FORMAT) |
Return Value:
The updated validation object
addJsonValidation
Add validations for a JSON field - Must not be empty (unless allowEmpty is set to true) - Must be a valid JSON string
public addJsonValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true, int $depth = 512, int $flags): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validations to |
$field | **array | string** |
$allowEmpty | bool | Whether to allow an empty value for the field |
$depth | int | The maximum depth of the JSON string (default: 512) |
$flags | int | JSON flags to be used (default: 0) |
Return Value:
The updated validator object
addColorValidation
Add basic validations for the color field - Must not be empty (unless $allowEmpty is set to true) - Must be a valid hex color code
public addColorValidation(\Zemit\Filter\Validation $validator, array|string $field, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object |
$field | **array | string** |
$allowEmpty | bool | Whether empty values are allowed (default: true) |
Return Value:
The modified validation object
addIdValidation
Add basic validations for the id field - Must be an unsigned integer
public addIdValidation(\Zemit\Filter\Validation $validator, string $field = 'id'): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validation object to add validation rules to |
$field | string | The name of the field to add validations for (default: 'id') |
Return Value:
The updated validation object
addPositionValidation
Add position validation to a validator object.
public addPositionValidation(\Zemit\Filter\Validation $validator, string $field = 'position', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$field | string | The field name to apply the validation rules to. Default is 'position'. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the position validation added.
addSoftDeleteValidation
Add soft delete validation to a validator object.
public addSoftDeleteValidation(\Zemit\Filter\Validation $validator, string $field = 'deleted', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$field | string | The field name to apply the validation rules to. Default is 'deleted'. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the soft delete validation added.
addUuidValidation
Add UUID validation to a validator object.
public addUuidValidation(\Zemit\Filter\Validation $validator, string $field = 'uuid', bool $allowEmpty = false): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$field | string | The field name to apply the validation rules to. Default is 'uuid'. |
$allowEmpty | bool | Whether empty values are allowed. Default is false. |
Return Value:
The updated validator object with the UUID validation added.
addCrudValidation
Add CRUD validation to a validator object.
public addCrudValidation(\Zemit\Filter\Validation $validator, string $userIdField, string $dateField, bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$userIdField | string | The field name for the user ID validation rules. |
$dateField | string | The field name for the date validation rules. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the CRUD validation added.
addCreatedValidation
Add created validation to a validator object.
public addCreatedValidation(\Zemit\Filter\Validation $validator, string $createdByField = 'createdBy', string $createdAtField = 'createdAt', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$createdByField | string | The field name to apply the validation rules for the "created by" user. Default is 'createdBy'. |
$createdAtField | string | The field name to apply the validation rules for the "created at" timestamp. Default is 'createdAt'. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the created validation added.
addUpdatedValidation
Add updated validation to a validator object.
public addUpdatedValidation(\Zemit\Filter\Validation $validator, string $updatedByField = 'updatedBy', string $updatedAtField = 'updatedAt', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$updatedByField | string | The field name to apply the updated by validation rule to. Default is 'updatedBy'. |
$updatedAtField | string | The field name to apply the updated at validation rule to. Default is 'updatedAt'. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the updated validation added.
addDeletedValidation
Add deleted validation to a validator object.
public addDeletedValidation(\Zemit\Filter\Validation $validator, string $deletedField = 'deletedBy', string $dateField = 'deletedAt', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$deletedField | string | The field name to apply the validation rules to for deleted user. Default is 'deletedBy'. |
$dateField | string | The field name to apply the validation rules to for deletion date. Default is 'deletedAt'. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the deleted validation added.
addRestoredValidation
Add restored validation to a validator object.
public addRestoredValidation(\Zemit\Filter\Validation $validator, string $restoredByField = 'restoredBy', string $restoredAtField = 'restoredAt', bool $allowEmpty = true): \Zemit\Filter\Validation
Parameters:
Parameter | Type | Description |
---|---|---|
$validator | \Zemit\Filter\Validation | The validator object to add the validation rules to. |
$restoredByField | string | The field name for the restored by information. Default is 'restoredBy'. |
$restoredAtField | string | The field name for the restored at information. Default is 'restoredAt'. |
$allowEmpty | bool | Whether empty values are allowed. Default is true. |
Return Value:
The updated validator object with the restored validation added.