php-arsenal / symfony-request-param-bagger
Collects sent parameters from Symfony Request and outputs an array.
Installs: 4 011
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=8.0.0
- symfony/http-foundation: ^5.3
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Collects sent parameters from Request and returns them in an array.
Features:
- assign default values
- cast to a specific type
- returns an array
Usage
Request example
{ "type": "gold", "size": "20", "amount": "1.23" }
Parse example
<?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); // ...
Output
array(3) {
["type"]=>
string(4) "gold"
["size"]=>
int(20)
["amount"]=>
float(1.23)
}