ajgarlag / psr-http-message-bundle

安装次数: 433,090

依赖项: 2

建议者: 0

安全性: 0

星标: 8

关注者: 2

分支: 2

开放问题: 1

类型:symfony-bundle

1.2.2 2022-09-28 11:23 UTC

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\RequestSymfony\Component\HttpFoundation\Response实例。

sensio/framework-extra-bundle升级到PSR-7支持

如果您的代码依赖于sensio/framework-extra-bundle的PSR-7支持,这是建议的升级路径

  1. 需要sensio/framework-extra-bundle:^5.3
  2. 需要ajgarlag/psr-http-message-bundle:^1.1,并启用旧服务的别名。
  3. sensio_framework_extra配置中禁用PSR-7支持。
  4. 如果您的代码依赖于旧的sensio_framework_extra.psr7.http_(message|foundation)_factory服务标识符,根据弃用消息修改服务定义以使用Symfony\Bridge\PsrHttpMessage\Http(Message|Foundation)Interface的替代方案。
  5. 您是否需要由sensio/framework-extra-bundle提供的其他功能?
    • 是:需要sensio/framework-extra-bundle:^6.0
    • 否:删除sensio/framework-extra-bundle

许可证

此组件受MIT许可证的约束。请参阅LICENSE文件中的完整许可证。

报告问题或功能请求

问题和功能请求在Github问题跟踪器中跟踪。

作者信息

Antonio J. García Lagar开发。

如果您认为此组件很有用,请在GitHub存储库页面和/或Packagist包页面上添加★。