loophp / psr-http-message-bridge-bundle

Register symfony/psr-http-message-bridge classes in your Symfony application.
MIT License
3 stars 1 forks source link

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:

Requirements

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.