Browse files

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 3a006b7.
  • Loading branch information...
1 parent 68a3944 commit 05d19d9a824aa48c5808393edf13079485bd3889 @chillu chillu committed Dec 18, 2011
Showing with 11 additions and 19 deletions.
  1. +11 −19 core/Convert.php
View
30 core/Convert.php
@@ -170,13 +170,9 @@ static function array2json($val) {
* @return mixed JSON safe string
*/
static function json2obj($val) {
- if(function_exists('json_decode')) {
- return json_decode($val);
- } else {
- require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
- $json = new Services_JSON();
- 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 @@ static function json2obj($val) {
* @return array|boolean
*/
static function json2array($val) {
- if(function_exists('json_decode')) {
- return json_decode($val, true);
- } else {
- $json = self::json2obj($val);
- if(!$json) return false;
-
- $arr = array();
- foreach($json as $k => $v) {
- $arr[$k] = $v;
- }
-
- return $arr;
+ $json = self::json2obj($val);
+ if(!$json) return false;
+
+ $arr = array();
+ foreach($json as $k => $v) {
+ $arr[$k] = $v;
}
+
+ return $arr;
}
/**

3 comments on commit 05d19d9

@chillu
SilverStripe Ltd. member

@simonwelsh This change is breaking the (admittedly faulty) API. While I think the change in general is a good idea (mainly for performance reasons), it needs more testing (both fixing UTs and checking JS like batch actions).

@sminnee
SilverStripe Ltd. member

Which tests does it break?

@chillu
SilverStripe Ltd. member

CMSMainTest and LeftAndMainTest

Please sign in to comment.