This commit is contained in:
as2252258@163.com
2021-09-05 04:56:56 +08:00
parent 0b7485e9da
commit cec0404b1f
+69
View File
@@ -118,6 +118,75 @@ class Request implements RequestInterface
} }
/**
* @param $name
* @param $required
* @return mixed
* @throws \Exception
*/
public function string($name, $required)
{
if (is_null($data = $this->post($name))) {
if ($required) {
throw new \Exception('Parameter is required and cannot be empty.');
}
}
return $data;
}
/**
* @param $name
* @param $required
* @return mixed
* @throws \Exception
*/
public function int($name, $required)
{
if (is_null($data = $this->post($name))) {
if ($required) {
throw new \Exception('Parameter is required and cannot be empty.');
}
}
return (string)$data;
}
/**
* @param $name
* @param $required
* @return mixed
* @throws \Exception
*/
public function float($name, $required)
{
if (is_null($data = $this->post($name))) {
if ($required) {
throw new \Exception('Parameter is required and cannot be empty.');
}
}
return (float)$data;
}
/**
* @param $name
* @param $required
* @return mixed
* @throws \Exception
*/
public function array($name, $required)
{
if (is_null($data = $this->post($name))) {
if ($required) {
throw new \Exception('Parameter is required and cannot be empty.');
}
}
if (!is_array($data)) return [];
return $data;
}
/** /**
* @return array|null * @return array|null
*/ */