Skip to content

RequestDtoMapper

Constructs a #[MapRequest] DTO instance from an already-validated WebRequest.

Must only be called after ValidationMiddleware’s ValidationManager::execute() has passed — property names are only readable via WebRequest::getParameter() once whitelisted by their RequestDtoScanner-registered validators (see Quiote\Action\Action::registerValidators()).

Scalar casting/normalization (int/float parsing, boolean literalization) has already happened inside NumberValidator/BooleanValidator during validation, which persist the cast value back into the request’s runtime parameters — this class mostly passes values through, only handling the shapes those validators don’t already normalize (JSON-encoded arrays, DateTimeImmutable, backed enums).

final class RequestDtoMapper

Since1.0.0
SourceRequest/RequestDtoMapper.php
MethodDescription
map(WebRequest $request, string $dtoClass): objectInstantiates $dtoClass from the request’s validated parameters.

public static function map(WebRequest $request, string $dtoClass): object

Instantiates $dtoClass from the request’s validated parameters.

Every property of the cached definition is resolved in declaration order and passed to the constructor by name. A parameter the request does not carry falls back to the property’s default, then to null when it is nullable.

ParameterTypeDescription
$requestWebRequest
$dtoClassstring

Returns object

ThrowsWhen
RuntimeExceptionwhen a required property is absent — which means the registered validator did not actually enforce it — or a present value cannot be coerced to the property’s declared type