delolmo / valinor-http-message
Map PSR-7 server requests (query params, parsed body and attributes) to typed PHP objects with cuyz/valinor.
Package info
github.com/delolmo/valinor-http-message
Language:Shell
pkg:composer/delolmo/valinor-http-message
Requires
- php: ~8.4.27 || ^8.5.12
- cuyz/valinor: ^2.6
- psr/http-message: ^1.1 || ^2.0
Requires (Dev)
- captainhook/captainhook-phar: ^5.29
- captainhook/plugin-composer: ^5.3
- doctrine/coding-standard: ^14.0
- ergebnis/composer-normalize: ^2.54
- infection/infection: ^0.35
- laminas/laminas-diactoros: ^3.6
- php-parallel-lint/php-parallel-lint: ^1.4
- phpstan/phpstan: ^2.3
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.1
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^13.4
- psalm/plugin-phpunit: ^0.19
- ramsey/conventional-commits: ^1.7
- rector/rector: ^2.8
- roave/security-advisories: dev-latest
- shipmonk/composer-dependency-analyser: ^1.8
- vimeo/psalm: ^6.20
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-29 08:32:30 UTC
README
Use a PSR-7 ServerRequestInterface as a source for the cuyz/valinor mapper.
Warning
This package is deprecated. Since 2.4, Valinor maps PSR-7 requests itself through HttpRequest::fromPsr(), which also maps controller arguments and can pin each value to the route, query or body. 2.6.3 is the last release; use cuyz/valinor directly instead. See Migrating to Valinor's HttpRequest.
Migrating to Valinor's HttpRequest
Replace the source with HttpRequest::fromPsr(), passing the request attributes as the route parameters:
-use CuyZ\Valinor\Mapper\Source\Source; -use DelOlmo\Valinor\Mapper\Source\ServerRequestSource; +use CuyZ\Valinor\Mapper\Http\HttpRequest; -$source = Source::iterable(new ServerRequestSource($request)); +$source = HttpRequest::fromPsr($request, $request->getAttributes()); $mapped = $mapper->map(CustomObject::class, $source);
Then composer remove delolmo/valinor-http-message. Two behaviours change:
- A key found in more than one of the route parameters, query params and parsed body is a mapping error, where this package let attributes win over query params and query params over the parsed body. Send the key in one place, or target it with
#[FromRoute],#[FromQuery]or#[FromBody]. - A parsed body that is an object throws
PsrRequestParsedBodyIsObject, where this package left it out.
Requirements
- PHP ~8.4.27 || ^8.5.12
- cuyz/valinor ^2.6
Installation
composer require delolmo/valinor-http-message
Example
use App\DTO\CustomObject; use CuyZ\Valinor\Mapper\Source\Source; use CuyZ\Valinor\MapperBuilder; use DelOlmo\Valinor\Mapper\Source\ServerRequestSource; use Psr\Http\Message\ServerRequestInterface; final class CustomController { public function execute(ServerRequestInterface $request) { // Create the source from the request $source = Source::iterable(new ServerRequestSource($request)); // Create the mapper, using the desired configuration $mapper = new MapperBuilder() ->allowSuperfluousKeys() ->allowScalarValueCasting() ->mapper(); // Map the source to whatever object makes sense $mapped = $mapper->map(CustomObject::class, $source); // Apply whatever business logic makes sense from here // ... } }
What the source holds
The source merges three parts of the request. When they share a key, the later one wins:
- the parsed body (
getParsedBody()), when it is an array; - the query params (
getQueryParams()); - the attributes (
getAttributes()), such as route parameters a router stored.
A parsed body that is null or an object is left out, and so are uploaded files.
Final notes
- Major versions of
delolmo/valinor-http-messagefollow the major versions ofcuyz/valinor. - Query and body params mostly arrive as strings, so the mapper usually needs
allowScalarValueCasting(). See the Valinor documentation on type strictness. - A request usually carries more than the target object needs (attributes stored by middlewares, for one), so the mapper usually needs
allowSuperfluousKeys()too.