PrepareDate
Prepares a date parameter of a controller request.
This trait resolves a date value (formatted with the Y-m-d pattern by default, or
the ControllerParam::DATE_FORMAT argument) from the route arguments or the
matching controller property, falling back to the current day when the candidate is
not a valid date. The request query string may override it, and only a valid query
value is written back into the parameter bag.
Tags
Table of Contents
Methods
- prepareDate() : string|null
- Prepares and returns a date string.
Methods
prepareDate()
Prepares and returns a date string.
protected
prepareDate(ServerRequestInterface|null $request[, array<string|int, mixed> $args = [] ][, array<string|int, mixed>|null &$params = null ][, string|null $default = null ][, string $name = Prop::DATE ]) : string|null
The value is read from $args[$name], then the $name property, then $default,
and is replaced by today's date when it does not match the resolved format. A valid
$name query parameter overrides the value and is stored in $params.
Parameters
- $request : ServerRequestInterface|null
-
The incoming PSR-7 server request, or null when no request context is available.
- $args : array<string|int, mixed> = []
-
The route/controller arguments that may carry an initial date and a
dateFormatentry. - $params : array<string|int, mixed>|null = null
-
A reference to the parameter bag updated in place with the prepared date.
- $default : string|null = null
-
The fallback date used when neither the arguments nor the property provide a valid value.
- $name : string = Prop::DATE
-
The name of the date parameter to read and store (defaults to Prop::DATE).
Return values
string|null —The resolved, format-validated date string.