AfterRule extends Rule
Validates that a value is a date strictly **after** a reference moment — a drop-in replacement for the `after` rule that ships with Somnambulist.
The shipped one cannot be used on a field that may be absent. It does not skip
a missing attribute : it hands null to a parameter typed string and dies
with a TypeError, and it raises a ParameterException on a value that is not
a date at all. Both are fatal, so a request carrying an optional date — or a
misspelt one — ends in a 500 instead of the validation failure it is.
Composing date|after:… does not help : the validation loop runs every rule of
an attribute, even after one has already failed, so the unsafe one is reached
anyway.
This one draws the line where it belongs, between the two sides of a validation :
- the value comes from a caller, so it never raises. Absent or empty, it
passes (declare
Rules::REQUIREDseparately when the field is mandatory) ; anything that is not a readable date — a number, a boolean, a list, plain nonsense — simply fails, which is what a422is made of ; - the reference comes from the declaration, so a broken one raises. A rule pointed at a moment nobody can read is a defect in the code, and silently refusing every request would hide it.
It is registered under the same name as the rule it replaces, so nothing
written against after has to change — only its behaviour does :
$validator->addRule( Rules::AFTER , new AfterRule() ) ;
// unchanged, and no longer fatal when the field is left out
[ 'validThrough' => after( 'yesterday' ) ]
The reference is any expression strtotime() understands, absolute or relative, exactly like the rule it stands in for.
Tags
Table of Contents
Constants
- NAME : string = \oihana\validations\enums\Rules::AFTER
- The rule name, as registered in the validation factory — the name of the rule it replaces.
- TIME : string = 'time'
- The name of the reference parameter.
Properties
- $fillableParams : array<int, string>
- The parameters filled from the `after:<reference>` expression.
- $message : string
- The message pattern used when the value is not a date after the reference.
Methods
- check() : bool
- Checks whether the given value is a date strictly after the reference.
- reference() : int
- The reference moment the value is compared against.
- timestamp() : int|null
- Reads a value as a unix timestamp, or null when it is not a readable date.
Constants
NAME
The rule name, as registered in the validation factory — the name of the rule it replaces.
public
string
NAME
= \oihana\validations\enums\Rules::AFTER
Tags
TIME
The name of the reference parameter.
public
string
TIME
= 'time'
Properties
$fillableParams
The parameters filled from the `after:<reference>` expression.
protected
array<int, string>
$fillableParams
= [self::TIME]
$message
The message pattern used when the value is not a date after the reference.
protected
string
$message
= "The :attribute must be a date after :time."
Methods
check()
Checks whether the given value is a date strictly after the reference.
public
check(mixed $value) : bool
Parameters
- $value : mixed
-
The value to validate.
Tags
Return values
bool —True when the value is absent, or a readable date after the reference.
reference()
The reference moment the value is compared against.
protected
reference() : int
Tags
Return values
inttimestamp()
Reads a value as a unix timestamp, or null when it is not a readable date.
protected
timestamp(mixed $value) : int|null
Parameters
- $value : mixed