delolmo/valinor-http-message 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

delolmo/valinor-http-message

最新稳定版本:2.3

Composer 安装命令:

composer require delolmo/valinor-http-message

包简介

Use psr/http-message as a Valinor source

README 文档

README

The following library allows using ServerRequestInterface objects of the psr/http-message library as a source for the cuyz/valinor library.

Installation

composer require delolmo/valinor-http-message

Example

use App\DTO\CustomObject;
use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\MapperBuilder;
use DelOlmo\Valinor\Mapping\Source\ServerRequestSource;
use Psr\Http\Message\ServerRequestInterface;

final class CustomController
{
    public function execute(ServerRequestInterface $request)
    {
        // Create the Source using the new InputSource
        $source = Source::iterable(new ServerRequestSource($input));
        
        // Create the Mapper, using the desired configuration
        $mapper = new MapperBuilder())
            ->allowSuperfluousKeys()
            ->enableFlexibleCasting()
            ->mapper();
            
        // Map the source to whatever object makes sense
        $mapped = $mapper->map(CustomObject::class, $source);
        
        // Apply whatever business logic makes sense from here
        // ...
    }
}

Final notes

  • Versioning of delolmo/valinor-http-message will always match cuyz/valinor versions. Same goes for PHP versions.
  • Although query params and body params should not share the same name in the Request, it should be noted that, from a ServerRequestSource standpoint, query params always take precedence over body params. That is, if there is a query param and a body param sharing the same name, ServerRequestSource will only use the query param's value for mapping purposes.
  • Considering that many query and body params are retrieved as strings or arrays, it is interesting to note that enableFlexibleCasting should also be configured in the Mapper. See Enabling flexible casting for more information.

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-01-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固