Pickles Framework Documentation

RequiredWhen
in package
implements ValidationRule

Class RequiredWhen

This class implements a validation rule that conditionally requires a field to be present based on a given condition. It is part of the validation rules in the Pickles Framework.

Tags
@implements

ValidationRule

Table of Contents

Interfaces

ValidationRule
Interface ValidationRule

Properties

$compareWith  : string
$operator  : string
$otherField  : string

Methods

__construct()  : mixed
message()  : string
Returns the validation error message.
validate()  : bool
Validates a field based on the presence and value of another field in the data array.

Properties

Methods

__construct()

public __construct(string $otherField, string $operator, string $compareWith) : mixed
Parameters
$otherField : string
$operator : string
$compareWith : string

message()

Returns the validation error message.

public message() : string
Tags
inheritDoc
Return values
string

The error message indicating the field must be a number.

validate()

Validates a field based on the presence and value of another field in the data array.

public validate(string $field, array<string|int, mixed> $data) : bool
Parameters
$field : string

The name of the field to validate.

$data : array<string|int, mixed>

The data array containing the fields and their values.

Return values
bool

Returns true if the field is valid based on the condition; otherwise, false.

The validation checks if the otherField exists in the data array. If it does, it evaluates the condition specified by the operator (=, >, <, >=, <=, !=) between the value of otherField and compareWith. If the condition is met, it checks if the $field exists in the data array and is not empty after trimming.


        
On this page

Search results