Skip to content
This repository
Browse code

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...
commit 05d19d9a824aa48c5808393edf13079485bd3889 1 parent 68a3944
Ingo Schommer authored December 18, 2011

Showing 1 changed file with 11 additions and 19 deletions. Show diff stats Hide diff stats

  1. 30  core/Convert.php
30  core/Convert.php
@@ -170,13 +170,9 @@ static function array2json($val) {
170 170
 	 * @return mixed JSON safe string
171 171
 	 */
172 172
 	static function json2obj($val) {
173  
-		if(function_exists('json_decode')) {
174  
-			return json_decode($val);
175  
-		} else {
176  
-			require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
177  
-			$json = new Services_JSON();
178  
-			return $json->decode($val);
179  
-		}
  173
+		require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
  174
+		$json = new Services_JSON();
  175
+		return $json->decode($val);
180 176
 	}
181 177
 
182 178
 	/**
@@ -187,19 +183,15 @@ static function json2obj($val) {
187 183
 	 * @return array|boolean
188 184
 	 */
189 185
 	static function json2array($val) {
190  
-		if(function_exists('json_decode')) {
191  
-			return json_decode($val, true);
192  
-		} else {
193  
-			$json = self::json2obj($val);
194  
-			if(!$json) return false;
195  
-			
196  
-			$arr = array();
197  
-			foreach($json as $k => $v) {
198  
-				$arr[$k] = $v;
199  
-			}
200  
-			
201  
-			return $arr;
  186
+		$json = self::json2obj($val);
  187
+		if(!$json) return false;
  188
+		
  189
+		$arr = array();
  190
+		foreach($json as $k => $v) {
  191
+			$arr[$k] = $v;
202 192
 		}
  193
+		
  194
+		return $arr;
203 195
 	}
204 196
 	
205 197
 	/**

3 notes on commit 05d19d9

Ingo Schommer
Owner

@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).

Sam Minnée
Owner

Which tests does it break?

Ingo Schommer
Owner

CMSMainTest and LeftAndMainTest

Please sign in to comment.
Something went wrong with that request. Please try again.