loophp / psr-http-message-bridge-bundle
在您的Symfony应用程序中注册symfony/psr-http-message-bridge类。
1.1.0
2024-08-21 14:28 UTC
Requires
- php: >= 8.2
- symfony/psr-http-message-bridge: ^7.1
Requires (Dev)
- drupol/php-conventions: ^5
- friends-of-phpspec/phpspec-code-coverage: ^6
- infection/infection: ^0.29
- infection/phpspec-adapter: ^0.2.0
- phpspec/phpspec: ^7.1
- symfony/framework-bundle: ^6.0
- symfony/http-kernel: ^6.0.0
This package is auto-updated.
Last update: 2024-08-28 07:55:20 UTC
README
PSR HTTP Message Bridge Bundle
此包将在您的Symfony应用程序容器中注册一些服务。
这些服务来自 symfony/psr-http-message-brige 桥接包。
它提供
-
一个参数值解析器,以便可以通过
Psr\Http\Message\MessageInterface
Psr\Http\Message\RequestInterface
Psr\Http\Message\ServerRequestInterface
这些是从当前Symfony Request对象直接派生出来的。
这意味着您可以直接通过方法参数在Symfony控制器中获取PSR7请求。
-
一个事件监听器,允许用户在Symfony控制器中返回PSR7响应。基本上,此事件将检查响应的返回值是否为
Psr\Http\Message\ResponseInterface
的实例,如果是,则将其转换为Symfony响应。 -
工厂
HttpFoundactionFactory
服务,用于将PSR请求转换为Symfony请求。PsrHttpFactory
服务,用于将Symfony请求转换为PSR请求。
要求
- PHP >= 7.3
- Symfony >= 4
安装
composer require loophp/psr-http-message-bridge-bundle
一旦包安装到您的应用程序中,即可使用,无需设置任何配置。
用法
<?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!')); } }
代码质量、测试和基准
每次向库引入更改时,Github 都会运行测试和基准测试。
库具有使用 PHPSpec 编写的测试。您可以在 spec
目录中自由查看它们。运行 composer phpspec
触发测试。
在每次提交之前,会使用 GrumPHP 执行一些检查,运行 ./vendor/bin/grumphp run
进行手动检查。
PHPInfection 用于确保您的代码得到适当的测试,运行 composer infection
测试您的代码。
贡献
请自由通过发送Github拉取请求来贡献。我非常积极 :-)
变更日志
查看 CHANGELOG.md 以获取基于 git提交 的变更日志。
有关更详细的变更日志,请检查 发布变更日志。