Search by

delolmo / valinor-http-message

delolmo

This package is abandoned and no longer maintained. The author suggests using the cuyz/valinor package instead.

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

Statistics

Installs: 35

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

2.6.3 2026-10-29 08:30 UTC

This package is auto-updated.

Last update: 2026-10-29 08:32:30 UTC


README

Packagist Version License: MIT

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:

  1. the parsed body (getParsedBody()), when it is an array;
  2. the query params (getQueryParams());
  3. 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-message follow the major versions of cuyz/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.