yiisoft / input-http
将PSR-7 HTTP请求中的数据映射到表示用户输入的PHP DTO。
1.0.1
2024-08-06 12:42 UTC
Requires
- php: ^8.1
- psr/container: ^1.0|^2.0
- psr/http-message: ^1.0|^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- yiisoft/arrays: ^3.0
- yiisoft/hydrator: ^1.0
- yiisoft/hydrator-validator: ^2.0
- yiisoft/middleware-dispatcher: ^5.1
- yiisoft/request-provider: ^1.0
- yiisoft/validator: ^1.1|^2.0
Requires (Dev)
- maglnet/composer-require-checker: ^4.7
- phpunit/phpunit: ^10.5
- rector/rector: ^1.0.0
- roave/infection-static-analysis-plugin: ^1.34
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^5.22
- yiisoft/di: ^1.2
- yiisoft/test-support: ^3.0
This package is auto-updated.
Last update: 2024-09-06 13:00:11 UTC
README
Yii Input HTTP
该包提供了Yii Hydrator属性,用于从PSR-7 HTTP请求中获取数据,并为Yii Middleware Dispatcher处理的中间件添加额外功能
- 将PSR-7 HTTP请求中的数据映射到表示用户输入的PHP DTO;
- 使用Yii Hydrator参数属性来解析中间件参数。
要求
- PHP 8.1或更高版本。
安装
可以使用Composer安装此包。
composer require yiisoft/input-http
通用用法
Yii Input HTTP允许拥有以下属性类型的DTO
use Yiisoft\Input\Http\AbstractInput; use Yiisoft\Input\Http\Attribute\Data\FromBody; #[FromBody] final class UpdatePostInput extends AbstractInput { public int $id; public string $title; public string $description = ''; public string $content; }
并自动解析和填充它,例如,对于以下参数
final class UpdatePostController { public function update(UpdatePostInput $post): ResponseInterface { // ... /** @var ResponseInterface $response */ return $response; } }
基本步骤
- 配置存储请求。
- 配置参数解析器。
- 创建DTO(请求输入)。
- 使用本包提供的hydrator属性标记DTO属性。
- 将DTO类名作为类型提示添加到您想要解析的类方法参数中。
文档
如果您需要帮助或有任何问题,您可以访问Yii论坛。您也可以查看其他Yii社区资源。
许可证
Yii Input HTTP是免费软件。它根据BSD许可证发布。有关更多信息,请参阅LICENSE
。
由Yii软件维护。