Revert "MINOR Use json_decode() instead of the Services_JSON class if the function exists." - it breaks assumptions around Convert::json2array() only converting the *first* level of an object structure into an array, which in turn fails CMSMainTest and LeftAndMainTest (as well as some UI functionality relying on it). In order to introduce this change we have to fix these issues in a backwards compatible manner.

This reverts commit 3a006b77ae.
This commit is contained in:
Ingo Schommer 2011-12-18 20:17:41 +01:00
parent 68a394427d
commit 05d19d9a82

View File

@ -170,13 +170,9 @@ class Convert {
* @return mixed JSON safe string * @return mixed JSON safe string
*/ */
static function json2obj($val) { static function json2obj($val) {
if(function_exists('json_decode')) { require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
return json_decode($val); $json = new Services_JSON();
} else { return $json->decode($val);
require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
$json = new Services_JSON();
return $json->decode($val);
}
} }
/** /**
@ -187,19 +183,15 @@ class Convert {
* @return array|boolean * @return array|boolean
*/ */
static function json2array($val) { static function json2array($val) {
if(function_exists('json_decode')) { $json = self::json2obj($val);
return json_decode($val, true); if(!$json) return false;
} else {
$json = self::json2obj($val); $arr = array();
if(!$json) return false; foreach($json as $k => $v) {
$arr[$k] = $v;
$arr = array();
foreach($json as $k => $v) {
$arr[$k] = $v;
}
return $arr;
} }
return $arr;
} }
/** /**