mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/10824] Add new helper function for decoding and sanitizing in place
PHPBB3-10824
This commit is contained in:
parent
ca4fdeaf2b
commit
5dc2e500f5
1 changed files with 15 additions and 1 deletions
|
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue