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\MessageInterfacePsr\Http\Message\RequestInterfacePsr\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\ResponseInterfaceand only if it's the case, will convert it into a Symfony response. -
Factories:
- A
HttpFoundactionFactoryservice to convert PSR requests into Symfony requests. - A
PsrHttpFactoryservice to convert Symfony requests into PSR requests.
- A
- PHP >= 7.3
- Symfony >= 4
composer require loophp/psr-http-message-bridge-bundleOnce the bundle installed in your application, it's ready to use, there is no configuration to set up.
<?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!'));
}
}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.
Feel free to contribute by sending Github pull requests. I'm quite responsive :-)
See CHANGELOG.md for a changelog based on git commits.
For more detailed changelogs, please check the release changelogs.