Oihana PHP

ComparisonRule extends Rule

AbstractYes

Base class for numeric comparison rules.

Provides common logic for comparing a field value against another field or a fixed numeric value.

Tags
author

Marc Alcaraz

since
1.0.0

Table of Contents

Constants

COMPARISON_FIELD  : string = 'comparison_field'
The 'comparison_field' parameter.

Properties

$fillableParams  : array<string|int, mixed>

Methods

check()  : bool
Performs the comparison between the attribute value and the comparison value.
compare()  : bool
Must be implemented by subclasses to perform the actual comparison.
getComparisonValue()  : mixed
Get the comparison value from either a field name or a direct value

Constants

COMPARISON_FIELD

The 'comparison_field' parameter.

public string COMPARISON_FIELD = 'comparison_field'

Properties

$fillableParams

protected array<string|int, mixed> $fillableParams = [self::COMPARISON_FIELD]

Methods

check()

Performs the comparison between the attribute value and the comparison value.

public check(mixed $value) : bool
Parameters
$value : mixed

The value of the current attribute being validated.

Tags
throws
ParameterException

If the comparison parameter is missing.

Return values
bool —

True if the comparison succeeds, false otherwise.

compare()

Must be implemented by subclasses to perform the actual comparison.

protected abstract compare(float|int $a, float|int $b) : bool
Parameters
$a : float|int

The attribute value.

$b : float|int

The comparison value.

Return values
bool —

True if the rule condition is met.

getComparisonValue()

Get the comparison value from either a field name or a direct value

protected getComparisonValue(string $fieldOrValue) : mixed
Parameters
$fieldOrValue : string
On this page

Search results