Oihana PHP

GreaterThanRule extends ComparisonRule

Validation rule that ensures a given value is **greater than or equal to** another field's value or to a fixed numeric constant.

This rule can be used to enforce constraints between numeric fields (e.g. durations, limits, quotas) or to validate a value against a fixed threshold.

Usage examples

// Compare with another field
$validation = $validator->validate($data,
[
    'implicitHybridTokenLifetime' => 'gte_field:maximumAccessTokenExpiration',
]);

// Compare with a fixed value
$validation = $validator->validate($data,
[
    'timeout' => 'gte_field:3600',
]);

When validation fails, the default message is:

The :attribute must be less than :comparison_field.
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

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

Properties

$fillableParams  : array<string|int, mixed>
$message  : string

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]

$message

protected string $message = 'The :attribute must be greater than :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 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