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-messagewill always matchcuyz/valinorversions. 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
enableFlexibleCastingshould also be configured in the Mapper. See Enabling flexible casting for more information.
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-01-29