Hi,
in Slim3 , I use a BaseController to get or check some pieces of request, using the request service of the container.
I’ve no idea on how to reproduce it with Slim 4, or take an alternate way. Some help would be welcome.
Here is an example of what I do:
class BaseController
{
protected $container;
public function __construct($container)
{
$this->container = $container;
}
protected function parseBoolParam($param, $required = false, $default = null)
{
$value = $this->container->get('request')->getParam($param);
if (is_null($value)) {
if ($required) {
throw new \UnexpectedValueException(
sprintf("Param [%s] required.", $param));
}
return $default;
} else {
return in_array(strtolower($value), [1, 'true', 'yes', 'on', 'succeed']);
}
}
}
–
Pascal