ajgarlag / psr-http-message-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-08-28 15:59:21 UTC
README
此扩展包为PSR-7中定义的HTTP消息接口提供支持。[PSR-7](http://www.php-fig.org/psr/psr-7/)。它允许在控制器中注入Psr\Http\Message\ServerRequestInterface
的实例,并返回Psr\Http\Message\ResponseInterface
的实例。
初始代码借鉴自sensio/framework-extra-bundle,自6.0版本开始已移除对[PSR-7](http://www.php-fig.org/psr/psr-7/)的支持。
安装
要安装此组件的最新稳定版本,请打开控制台并执行以下命令
$ composer require ajgarlag/psr-http-message-bundle
注意,必须安装PSR-17的自动装配别名。一种简单的方法是要求nyholm/psr7
$ composer require nyholm/psr7
配置
如果您的代码依赖于旧的sensio_framework_extra_...
服务标识符,您应该启用别名定义
ajgarlag_psr_http_message: alias_sensio_framework_extra_services: enabled: true
用法
然后,可以直接在控制器中使用[PSR-7](http://www.php-fig.org/psr/psr-7/)消息,如下代码片段所示
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; } }
注意,在内部,Symfony始终使用Symfony\Component\HttpFoundation\Request
和Symfony\Component\HttpFoundation\Response
实例。
从sensio/framework-extra-bundle升级到PSR-7支持
如果您的代码依赖于sensio/framework-extra-bundle的PSR-7支持,这是建议的升级路径
- 需要
sensio/framework-extra-bundle:^5.3
。 - 需要
ajgarlag/psr-http-message-bundle:^1.1
,并启用旧服务的别名。 - 在
sensio_framework_extra
配置中禁用PSR-7支持。 - 如果您的代码依赖于旧的
sensio_framework_extra.psr7.http_(message|foundation)_factory
服务标识符,根据弃用消息修改服务定义以使用Symfony\Bridge\PsrHttpMessage\Http(Message|Foundation)Interface
的替代方案。 - 您是否需要由
sensio/framework-extra-bundle
提供的其他功能?- 是:需要
sensio/framework-extra-bundle:^6.0
。 - 否:删除
sensio/framework-extra-bundle
。
- 是:需要
许可证
此组件受MIT许可证的约束。请参阅LICENSE文件中的完整许可证。
报告问题或功能请求
问题和功能请求在Github问题跟踪器中跟踪。
作者信息
如果您认为此组件很有用,请在GitHub存储库页面和/或Packagist包页面上添加★。