Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Request Mapper Laravel Package

devouted/request-mapper

View on GitHub
Deep Wiki
Context7

Request Mapper

PHP Version Tested on PHP 8.5 Symfony License

Symfony attributes for mapping HTTP request headers, path parameters and uploaded files to object constructor parameters via the Serializer denormalization pipeline.

Requirements

  • PHP >= 8.2 (tested on 8.2, 8.3, 8.4, 8.5)
  • Symfony 6.4, 7.x or 8.x

Installation

composer require devouted/request-mapper

Usage

Mark constructor parameters with attributes to indicate their source:

use RequestMapper\Attribute\FromHeader;
use RequestMapper\Attribute\FromPath;
use RequestMapper\Attribute\FromUploads;

class GetArticleQuery
{
    public function __construct(
        #[FromPath]
        public int $articleId,

        #[FromHeader(name: 'Accept-Language')]
        public string $language,
    ) {
    }
}

class UploadFileCommand
{
    public function __construct(
        #[FromPath]
        public int $visitId,

        #[FromUploads]
        public array $files = [],
    ) {
    }
}

Attributes

Attribute Source Example
#[FromHeader] HTTP request header #[FromHeader(name: 'X-Token')]
#[FromPath] Route parameter #[FromPath(name: 'id')]
#[FromUploads] Uploaded files ($_FILES) #[FromUploads]

All attributes accept optional name (defaults to parameter name) and required (defaults to true).

#[FromPath] automatically casts values to the parameter's PHP type (int, float, bool, string).

Value Resolver

The bundle includes RequestMapperValueResolver which integrates with Symfony's #[MapQueryString] and #[MapRequestPayload] attributes. This solves the problem where Symfony's default resolver skips mapping entirely when the query string or request body is empty — preventing FromHeader, FromPath and FromUploads attributes from being processed.

use RequestMapper\Attribute\FromHeader;
use RequestMapper\Attribute\FromPath;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;

class ArticleController
{
    public function show(#[MapQueryString] GetArticleQuery $query): Response
    {
        // Works even when the query string is empty —
        // FromPath and FromHeader attributes are still resolved.
    }
}

The resolver requires symfony/http-kernel and symfony/validator.

Configuration

If Symfony autoconfiguration is enabled, the denormalizer and value resolver are registered automatically. Otherwise register them manually:

# config/services.yaml
services:
    RequestMapper\Serializer\RequestMapperDenormalizer:
        tags: ['serializer.normalizer']

    RequestMapper\ArgumentResolver\RequestMapperValueResolver:
        tags: ['controller.argument_value_resolver']
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views