Request parameter manager is PHP package for object oriented way to get request (post, get) parameters. Also supports value parser to parse parameters value into format you want.
Just require via composer
composer install thecookieshows/request-parameter-manager
Create new instance of RequestManager. First parameter is array of RequestParameters, second is instance of ParameterBag
$queryManager = new QueryManager([new QueryParameter('id')], $request->request);
Constructor of request parameter
- Name of parameter
- Default value (default is "")
- Is Required (default is False)
$queryParameter = new QueryParameter('id', '1', false);
$id = $queryManager->getParameterValue('id');
Pass instance of parser into setParser() method
$requestParameter->setParser(new DateParser();
Just implement ParserInterface
class DatetimeParser implements ParserInterface
{
public function parse(string $input, string $format = "d-m-Y H:i:s") : \DateTime
{
return \DateTime::createFromFormat($format, $input);
}
}