ajgarlag / psr-http-message-bundle
Installs: 451 582
Dependents: 2
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 2
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=7.4
- psr/http-factory: ^1.0
- symfony/dependency-injection: ^5.4|^6.0
- symfony/framework-bundle: ^5.4|^6.0
- symfony/psr-http-message-bridge: ^1.1|^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nyholm/psr7: ^1.1
- phpunit/phpunit: ^9.5
- sensio/framework-extra-bundle: ^5.5.4|^6.2.6
- symfony/browser-kit: ^5.4|^6.0
- symfony/monolog-bridge: ^5.4|^6.0
- symfony/monolog-bundle: ^3.2
- symfony/phpunit-bridge: ^6.1
- symfony/yaml: ^5.4|^6.0
Suggests
- nyholm/psr7: Provides autowiring aliases for PSR-17
Conflicts
This package is auto-updated.
Last update: 2024-10-28 16:32:44 UTC
README
This bundle provides support for HTTP messages interfaces defined
in PSR-7. It allows to inject instances of Psr\Http\Message\ServerRequestInterface
and to return instances of Psr\Http\Message\ResponseInterface
in controllers.
The inital code is borrowed from sensio/framework-extra-bundle which removed support for PSR-7 since version 6.0.
Installation
To install the latest stable version of this component, open a console and execute the following command:
$ composer require ajgarlag/psr-http-message-bundle
Note that autowiring aliases for PSR-17 must be installed. An easy way to provide them is to require nyholm/psr7 :
$ composer require nyholm/psr7
Configuration
If your code depends on old sensio_framework_extra_...
services identifiers, you should enable aliasing defining:
ajgarlag_psr_http_message: alias_sensio_framework_extra_services: enabled: true
Usage
Then, PSR-7 messages can be used directly in controllers like in the following code snippet
namespace App\Controller; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ServerRequestInterface; class DefaultController { public function index(ServerRequestInterface $request, ResponseFactoryInterface $responseFactory) { // Interact with the PSR-7 request $response = $responseFactory->createResponse(); // Interact with the PSR-7 response return $response; } }
Note that internally, Symfony always use Symfony\Component\HttpFoundation\Request
and Symfony\Component\HttpFoundation\Response
instances.
Upgrade path from sensio/framework-extra-bundle PSR-7 support
If your code depends on sensio/framework-extra-bundle PSR-7 support, this is the suggested upgrade path:
- Require
sensio/framework-extra-bundle:^5.3
. - Require
ajgarlag/psr-http-message-bundle:^1.1
, and enable old services aliasing. - Disable PSR-7 support in
sensio_framework_extra
configuration. - If your code depends on old
sensio_framework_extra.psr7.http_(message|foundation)_factory
services identifiers, modify service definitions to use theSymfony\Bridge\PsrHttpMessage\Http(Message|Foundation)Interface
alternatives following deprecation messages. - Do you need any other feature provided by
sensio/framework-extra-bundle
?:- YES: require
sensio/framework-extra-bundle:^6.0
. - NO: remove
sensio/framework-extra-bundle
.
- YES: require
License
This component is under the MIT license. See the complete license in the LICENSE file.
Reporting an issue or a feature request
Issues and feature requests are tracked in the Github issue tracker.
Author Information
Developed with ♥ by Antonio J. García Lagar.
If you find this component useful, please add a ★ in the GitHub repository page and/or the Packagist package page.