From 572ba1695b8cb9d7df6738c38488eb1830d626aa Mon Sep 17 00:00:00 2001 From: Alex Blackham Date: Fri, 21 Jun 2019 10:44:31 +0100 Subject: [PATCH 1/3] The input()->all method will now set every key specified in the filter. If the key doesn't exist it will be set to null. --- src/Pecee/Http/Input/InputHandler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Pecee/Http/Input/InputHandler.php b/src/Pecee/Http/Input/InputHandler.php index f05bf10..07c68d1 100644 --- a/src/Pecee/Http/Input/InputHandler.php +++ b/src/Pecee/Http/Input/InputHandler.php @@ -303,13 +303,22 @@ class InputHandler // Append any PHP-input json if (strpos(trim($contents), '{') === 0) { $post = json_decode($contents, true); + if ($post !== false) { $output += $post; } } } - return (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output; + $output = (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output; + + foreach ($filter as $value) { + if (!array_key_exists($value, $output)) { + $output[$value] = null; + } + } + + return $output; } /** From 93c0622b9da90bc688d26197ffaabd0a14a626be Mon Sep 17 00:00:00 2001 From: Alex Blackham Date: Fri, 21 Jun 2019 10:45:57 +0100 Subject: [PATCH 2/3] Altered variable name in foreach to be less ambiguous. --- src/Pecee/Http/Input/InputHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Pecee/Http/Input/InputHandler.php b/src/Pecee/Http/Input/InputHandler.php index 07c68d1..69690dc 100644 --- a/src/Pecee/Http/Input/InputHandler.php +++ b/src/Pecee/Http/Input/InputHandler.php @@ -312,9 +312,9 @@ class InputHandler $output = (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output; - foreach ($filter as $value) { - if (!array_key_exists($value, $output)) { - $output[$value] = null; + foreach ($filter as $filterKey) { + if (!array_key_exists($filterKey, $output)) { + $output[$filterKey] = null; } } From 891c2092eb0ec4f5232c07e9d1c4883ccc06ea1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Wed, 17 Mar 2021 19:25:18 +0100 Subject: [PATCH 3/3] Changed codestyle to match the rest --- src/Pecee/Http/Input/InputHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pecee/Http/Input/InputHandler.php b/src/Pecee/Http/Input/InputHandler.php index 69690dc..6d02116 100644 --- a/src/Pecee/Http/Input/InputHandler.php +++ b/src/Pecee/Http/Input/InputHandler.php @@ -313,7 +313,7 @@ class InputHandler $output = (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output; foreach ($filter as $filterKey) { - if (!array_key_exists($filterKey, $output)) { + if (array_key_exists($filterKey, $output) === false) { $output[$filterKey] = null; } } @@ -354,4 +354,4 @@ class InputHandler $this->file[$key] = $item; } -} \ No newline at end of file +}