Explorar el Código

[php] made php.Lib.objectOfAssociativeArray() recursive (fixes #6698)

Alexander Kuzmenko hace 7 años
padre
commit
93c7b63394
Se han modificado 3 ficheros con 22 adiciones y 2 borrados
  1. 1 0
      extra/CHANGES.txt
  2. 7 2
      std/php/Lib.hx
  3. 14 0
      tests/unit/src/unit/TestPhp.hx

+ 1 - 0
extra/CHANGES.txt

@@ -15,6 +15,7 @@
 	php : fixed `Sys.environment()` to also return variables set by `Sys.putEnv()`
 	php : fixed `sys.net.Socket.bind()` (#6693)
 	php : fixed appending "sqlite:" prefix to the names of files created by `sys.db.Sqlite.open()` (#6692)
+	php : made php.Lib.objectOfAssociativeArray() recursive (#6698)
 
 2017-10-08: 4.0.0-preview.2
 

+ 7 - 2
std/php/Lib.hx

@@ -107,7 +107,12 @@ class Lib {
 		return @:privateAccess hash.data;
 	}
 
-	public static inline function objectOfAssociativeArray(arr : NativeArray) : Dynamic {
+	public static function objectOfAssociativeArray(arr : NativeArray) : Dynamic {
+		Syntax.foreach(arr, function(key:Scalar, value:Dynamic) {
+			if(Global.is_array(value)) {
+				arr[key] = objectOfAssociativeArray(value);
+			}
+		});
 		return Boot.createAnon(arr);
 	}
 
@@ -136,7 +141,7 @@ class Lib {
 	}
 
 	/**
-		Tries to load all compiled php files and returns list of tpes.
+		Tries to load all compiled php files and returns list of types.
 	**/
 	public static function getClasses():Dynamic {
 		if(!loaded) {

+ 14 - 0
tests/unit/src/unit/TestPhp.hx

@@ -54,6 +54,20 @@ class TestPhp extends Test
 		f(Class2146.test());
 	}
 
+	function testIssue6698() {
+		var arr = new NativeAssocArray<Dynamic>();
+		var innerArr = new NativeAssocArray<Int>();
+		innerArr['one'] = 1;
+		innerArr['two'] = 2;
+		arr['inner'] = innerArr;
+
+		var obj = Lib.objectOfAssociativeArray(arr);
+		var innerObj = obj.inner;
+		t(Global.is_object(innerObj));
+		eq(1, innerObj.one);
+		eq(2, innerObj.two);
+	}
+
 	function testStupidShit9000() {
 		var f = make();
 		f.handle( function() {