php-arsenal / symfony-request-param-bagger
从Symfony Request中收集发送的参数并输出一个数组。
0.5.5
2023-07-21 08:25 UTC
Requires
- php: >=8.0.0
- symfony/http-foundation: ^5.3
Requires (Dev)
- phpunit/phpunit: ^9.5
README
从Request中收集发送的参数并以数组形式返回。
功能
- 分配默认值
- 转换为特定类型
- 返回数组
使用方法
请求示例
{ "type": "gold", "size": "20", "amount": "1.23" }
解析示例
<?php use PhpArsenal\SymfonyRequestParamBagger\RequestParamBagger; // ... #[Route('/api', methods: ['POST'], format: 'json')] public function postSomething( Request $request ): JsonResponse { $params = RequestParamBagger::build($request, [ 'type' => null, 'size' => null, 'amount' => null, ], [ 'type' => 'string', 'size' => 'int', 'amount' => 'float', ]); var_dump($params); // ...
输出
array(3) {
["type"]=>
string(4) "gold"
["size"]=>
int(20)
["amount"]=>
float(1.23)
}