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

Psr Http Message Bridge Bundle Laravel Package

loophp/psr-http-message-bridge-bundle

Symfony bundle that bridges PSR-7 HTTP messages with Symfony’s HttpFoundation, enabling smooth interop between PSR-7 libraries and Symfony apps. Provides converters/adapters to translate requests and responses in both directions.

View on GitHub
Deep Wiki
Context7

Latest Stable Version GitHub stars Total Downloads License Donate!

PSR HTTP Message Bridge Bundle

This bundle will register in your Symfony application's container a couple of services.

Those services are from the symfony/psr-http-message-brige bridge package.

It provides:

  • An argument value resolver to be able to get the following objects through:

    • Psr\Http\Message\MessageInterface
    • Psr\Http\Message\RequestInterface
    • Psr\Http\Message\ServerRequestInterface

    Those are directly derived from the current Symfony Request object.

    It means that you can directly get a PSR7 Request in Symfony controllers through method parameters.

  • An event listener that let users return PSR7 Responses in Symfony controllers. Basically, this event will check if the return value of a Response is an instance of Psr\Http\Message\ResponseInterface and only if it's the case, will convert it into a Symfony response.

  • Factories:

    • A HttpFoundactionFactory service to convert PSR requests into Symfony requests.
    • A PsrHttpFactory service to convert Symfony requests into PSR requests.

Requirements

  • PHP >= 7.3
  • Symfony >= 4

Installation

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

Once the bundle installed in your application, it's ready to use, there is no configuration to set up.

Usage

<?php

declare(strict_types=1);

namespace App\Controller;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

final class HelloWorldController {

    private ResponseFactoryInterface $responseFactory;
    private StreamFactoryInterface $streamFactory;

    public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
    {
        $this->responseFactory = $responseFactory;
        $this->streamFactory = $streamFactory;
    }

    /**
     * @Route("/hello-world", name="hello_world")
     */
    public function __invoke(RequestInterface $psrRequest): ResponseInterface {
        // You can do something with $psrRequest if needed.

        // Build the PSR response.
        $response = $this->responseFactory->createResponse();

        // Return the new PSR response.
        return $response->withBody($this->streamFactory->createStream('Hello world!'));
    }
}

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
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