yiisoft/input-http

将PSR-7 HTTP请求中的数据映射到表示用户输入的PHP DTO。

1.0.1 2024-08-06 12:42 UTC

This package is auto-updated.

Last update: 2024-09-06 13:00:11 UTC


README

Yii

Yii Input HTTP


Latest Stable Version Total Downloads Build status Code Coverage Mutation testing badge static analysis type-coverage psalm-level

该包提供了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;
    }
}

基本步骤

文档

如果您需要帮助或有任何问题,您可以访问Yii论坛。您也可以查看其他Yii社区资源

许可证

Yii Input HTTP是免费软件。它根据BSD许可证发布。有关更多信息,请参阅LICENSE

Yii软件维护。

支持项目

Open Collective

关注更新

Official website Twitter Telegram Facebook Slack