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

Unaltered Psr Http Message Bridge Bundle Laravel Package

loophp/unaltered-psr-http-message-bridge-bundle

Symfony bundle bridging PSR-7 HTTP messages without altering them. Converts between PSR-7 requests/responses and Symfony HttpFoundation safely, preserving headers, body streams, and URIs—useful when integrating PSR-7 middleware or clients in Symfony apps.

View on GitHub
Deep Wiki
Context7

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality Type Coverage Code Coverage License Donate! Donate!

Unaltered PSR HTTP Message Bridge Bundle

An opt-in and drop-in replacement bundle for symfony/psr-http-message-bridge that doesn't alter the query parameters.

This package register a decorator for the service PsrHttpFactory in your Symfony application.

The only difference with the original class from symfony/psr-http-message-bridge is that it doesn't alter the query parameters when converting a Symfony request into a PSR7 request.

Context:

TL;DR

Symfony's Request class uses parse_str() function to parse the query string, but parse_str() alter the parameter key if it contains . and replaces them with _. This issue makes the Request object harder to work with when we some logic needs to heavily rely on query parameters (API Platform, CAS, ... ).

Requirements

  • PHP >= 7.1.3
  • Symfony >= 4

Installation

composer require loophp/unaltered-psr-http-message-bridge-bundle

Usage

<?php

declare(strict_types=1);

namespace App\Controller;

use Psr\Http\Message\RequestInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;

final class MainController {
    /**
     * @Route("/api/offers", name="api_offers")
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function __invoke(
        Request $request,
        HttpMessageFactoryInterface $httpMessageFactory,
        RequestInterface $psrRequest
    ): Response {
        // Using Symfony's request object.
        $uri = $request->getUri(); // http://localhost:8000/api/offers?product_color=red
        $params = $request->query->all(); // [ 'product_color' => 'red' ]

        // Using PSR Request.
        $psrRequest = $httpMessageFactory->createRequest($request);
        $uri = (string) $psrRequest->getUri(); // http://localhost:8000/api/offers?product.color=red
        $params = $psrRequest->getUri()->getQuery(); // 'product.color=red'

        // Or directly by requesting the PSR request through RequestInterface parameter.

        return new Response('');
    }
}

Notice that the query string parameters has been altered, from field.filter to field_filter when using the Symfony Request object.

Configuration

There is no configuration and you do not have to do anything besides requiring this package in your application.

Code quality, tests and benchmarks

Every time changes are introduced into the library, Github run the tests and the benchmarks.

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests.

Before each commit some inspections are executed with GrumPHP, run ./vendor/bin/grumphp run to check manually.

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code.

Contributing

Feel free to contribute by sending Github pull requests. I'm quite responsive :-)

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

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.
monarobase/country-list
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity