diff --git a/application/core/EA_Input.php b/application/core/EA_Input.php index f4ef1b3d..80793a14 100644 --- a/application/core/EA_Input.php +++ b/application/core/EA_Input.php @@ -45,12 +45,12 @@ class EA_Input extends CI_Input { /** * Fetch an item from JSON data. * - * @param string $index Index for item to be fetched from the JSON payload. + * @param string|null $index Index for item to be fetched from the JSON payload. * @param bool|false $xss_clean Whether to apply XSS filtering * * @return mixed */ - public function json(string $index, bool $xss_clean = FALSE) + public function json(string $index = NULL, bool $xss_clean = FALSE) { /** @var EA_Controller $CI */ $CI = &get_instance(); @@ -69,8 +69,19 @@ class EA_Input extends CI_Input { $payload = json_decode($input_stream, TRUE); - $value = $payload[$index] ?? NULL; + if ($xss_clean) + { + foreach ($payload as $name => $value) + { + $payload[$name] = $CI->security->xss_clean($value); + } + } - return $value && $xss_clean ? $CI->security->xss_clean($value) : $value; + if (empty($index)) + { + return $payload; + } + + return $payload[$index] ?? NULL;; } } diff --git a/application/helpers/http_helper.php b/application/helpers/http_helper.php index 60595967..82c9c1b0 100644 --- a/application/helpers/http_helper.php +++ b/application/helpers/http_helper.php @@ -21,20 +21,27 @@ if ( ! function_exists('request')) * $first_name = request('first_name', 'John'); * * @param string|null $key Request variable key. - * @param mixed $default Default value in case the requested variable has no value. + * @param mixed|null $default Default value in case the requested variable has no value. * * @return mixed * * @throws InvalidArgumentException */ - function request(string $key, $default = NULL) + function request(string $key = NULL, $default = NULL) { /** @var EA_Controller $CI */ $CI = &get_instance(); if (empty($key)) { - throw new InvalidArgumentException('The $key argument cannot be empty.'); + $payload = $CI->input->post_get($key); + + if (empty($payload)) + { + $payload = $CI->input->json($key); + } + + return $payload; } return $CI->input->post_get($key) ?? $CI->input->json($key) ?? $default;