[ticket/10824] Add new helper function for decoding and sanitizing in place

PHPBB3-10824
This commit is contained in:
Marc Alexander 2018-12-28 10:59:54 +01:00
parent ca4fdeaf2b
commit 5dc2e500f5
No known key found for this signature in database
GPG key ID: 50E0D2423696F995

View file

@ -13,6 +13,8 @@
namespace phpbb; namespace phpbb;
use phpbb\request\type_cast_helper;
/** /**
* JSON sanitizer class * JSON sanitizer class
*/ */
@ -30,7 +32,7 @@ class json_sanitizer
if (!empty($data)) if (!empty($data))
{ {
$json_sanitizer = function (&$value, $key) { $json_sanitizer = function (&$value, $key) {
$type_cast_helper = new \phpbb\request\type_cast_helper(); $type_cast_helper = new type_cast_helper();
$type_cast_helper->set_var($value, $value, gettype($value), true); $type_cast_helper->set_var($value, $value, gettype($value), true);
}; };
array_walk_recursive($data, $json_sanitizer); array_walk_recursive($data, $json_sanitizer);
@ -38,4 +40,16 @@ class json_sanitizer
return $data; return $data;
} }
/**
* Decode and sanitize json data
*
* @param string $json JSON data string
*
* @return array Data array
*/
static public function decode($json)
{
return self::sanitize(json_decode($json, true));
}
} }